Skip to content

Commit

Permalink
fix: make frontend stock management only available if woocommerce all…
Browse files Browse the repository at this point in the history
…ows is fixed #654 (#655)

* fix: make frontend stock management only available if wocommerce allows is fixed #654

* fix: add dokan_get_translated_product_stock_status function
  • Loading branch information
saimonh3 authored and sabbir1991 committed Jul 24, 2019
1 parent 22065da commit 89ec714
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
19 changes: 19 additions & 0 deletions includes/product-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,23 @@ function dokan_get_vendor_by_product( $product ) {
}

return dokan()->vendor->get( $vendor_id );
}

/**
* Get translated product stock status
*
* @since DOKAN_LITE_SINCE
*
* @param mix $stock
*
* @return string | array if stock parameter is not provided
*/
function dokan_get_translated_product_stock_status( $stock = false ) {
$stock_status = wc_get_product_stock_status_options();

if ( ! $stock ) {
return $stock_status;
}

return isset( $stock_status[$stock] ) ? $stock_status[$stock] : '';
}
5 changes: 4 additions & 1 deletion templates/products/inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@

<?php dokan_post_input_box( $post_id, '_stock_status', array( 'options' => array(
'instock' => __( 'In Stock', 'dokan-lite' ),
'outofstock' => __( 'Out of Stock', 'dokan-lite' ),
'outofstock' => __( 'Out of Stock', 'dokan-lite' ),
'onbackorder' => __( 'On Backorder', 'dokan-lite' ),
) ), 'select' ); ?>
</div>

<div class="dokan-clearfix"></div>

<?php if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) : ?>
<div class="dokan-form-group hide_if_variation hide_if_grouped">
<?php dokan_post_input_box( $post_id, '_manage_stock', array( 'label' => __( 'Enable product stock management', 'dokan-lite' ) ), 'checkbox' ); ?>
</div>
Expand Down Expand Up @@ -55,6 +57,7 @@
</div>
<div class="dokan-clearfix"></div>
</div><!-- .show_if_stock -->
<?php endif; ?>

<div class="dokan-form-group hide_if_grouped">
<label class="" for="_sold_individually">
Expand Down
6 changes: 1 addition & 5 deletions templates/products/products-listing-row.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@
</td>
<td data-title="<?php esc_attr_e( 'Stock', 'dokan-lite' ); ?>">
<?php
if ( $product->is_in_stock() ) {
echo '<mark class="instock">' . esc_html__( 'In stock', 'dokan-lite' ) . '</mark>';
} else {
echo '<mark class="outofstock">' . esc_html__( 'Out of stock', 'dokan-lite' ) . '</mark>';
}
echo '<mark class="' . $product->get_stock_status() . '">' . esc_html( dokan_get_translated_product_stock_status( $product->get_stock_status() ) ) . '</mark>';

if ( $product->managing_stock() ) :
echo ' &times; ' . esc_html( $product->get_stock_quantity() );
Expand Down

0 comments on commit 89ec714

Please sign in to comment.