Merge pull request #5353 from tamarazuk/backorder-variations
Backorders at variation level
This commit is contained in:
commit
3e1d5feaf3
|
@ -735,6 +735,13 @@ class WC_Meta_Box_Product_Data {
|
|||
if ( $tax_classes )
|
||||
foreach ( $tax_classes as $class )
|
||||
$tax_class_options[ sanitize_title( $class ) ] = esc_attr( $class );
|
||||
|
||||
$backorder_options = array(
|
||||
'no' => __( 'Do not allow', 'woocommerce' ),
|
||||
'notify' => __( 'Allow, but notify customer', 'woocommerce' ),
|
||||
'yes' => __( 'Allow', 'woocommerce' )
|
||||
);
|
||||
|
||||
?>
|
||||
<div id="variable_product_options" class="panel wc-metaboxes-wrapper"><div id="variable_product_options_inner">
|
||||
|
||||
|
@ -786,7 +793,8 @@ class WC_Meta_Box_Product_Data {
|
|||
'length' => wc_format_localized_decimal( get_post_meta( $post->ID, '_length', true ) ),
|
||||
'width' => wc_format_localized_decimal( get_post_meta( $post->ID, '_width', true ) ),
|
||||
'height' => wc_format_localized_decimal( get_post_meta( $post->ID, '_height', true ) ),
|
||||
'tax_class' => get_post_meta( $post->ID, '_tax_class', true )
|
||||
'tax_class' => get_post_meta( $post->ID, '_tax_class', true ),
|
||||
'backorder_options' => $backorder_options
|
||||
);
|
||||
|
||||
if ( ! $parent_data['weight'] )
|
||||
|
@ -844,7 +852,8 @@ class WC_Meta_Box_Product_Data {
|
|||
|
||||
foreach ( $variation_fields as $field )
|
||||
$$field = isset( $variation_data[ $field ][0] ) ? maybe_unserialize( $variation_data[ $field ][0] ) : '';
|
||||
|
||||
|
||||
$_backorders = isset( $variation_data['_backorders'][0] ) ? $variation_data['_backorders'][0] : null;
|
||||
$_tax_class = isset( $variation_data['_tax_class'][0] ) ? $variation_data['_tax_class'][0] : null;
|
||||
$image_id = absint( $_thumbnail_id );
|
||||
$image = $image_id ? wp_get_attachment_thumb_url( $image_id ) : '';
|
||||
|
@ -1336,6 +1345,7 @@ class WC_Meta_Box_Product_Data {
|
|||
$variable_width = isset( $_POST['variable_width'] ) ? $_POST['variable_width'] : array();
|
||||
$variable_height = isset( $_POST['variable_height'] ) ? $_POST['variable_height'] : array();
|
||||
$variable_stock = isset( $_POST['variable_stock'] ) ? $_POST['variable_stock'] : array();
|
||||
$variable_backorders = isset( $_POST['variable_backorders'] ) ? $_POST['variable_backorders'] : array();
|
||||
$variable_enabled = isset( $_POST['variable_enabled'] ) ? $_POST['variable_enabled'] : array();
|
||||
$variable_is_virtual = isset( $_POST['variable_is_virtual'] ) ? $_POST['variable_is_virtual'] : array();
|
||||
$variable_is_downloadable = isset( $_POST['variable_is_downloadable'] ) ? $_POST['variable_is_downloadable'] : array();
|
||||
|
@ -1403,6 +1413,12 @@ class WC_Meta_Box_Product_Data {
|
|||
if ( isset( $variable_stock[$i] ) ) {
|
||||
wc_update_product_stock( $variation_id, wc_clean( $variable_stock[ $i ] ) );
|
||||
}
|
||||
|
||||
// Backorders
|
||||
if ( isset( $variable_backorders[ $i ] ) && $variable_backorders[ $i ] !== 'parent' )
|
||||
update_post_meta( $variation_id, '_backorders', wc_clean( $variable_backorders[ $i ] ) );
|
||||
else
|
||||
delete_post_meta( $variation_id, '_backorders' );
|
||||
|
||||
// Price handling
|
||||
$regular_price = wc_format_decimal( $variable_regular_price[ $i ] );
|
||||
|
|
|
@ -64,7 +64,15 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||
<label><?php _e( 'Stock Qty:', 'woocommerce' ); ?> <a class="tips" data-tip="<?php _e( 'Enter a quantity to enable stock management at variation level, or leave blank to use the parent product\'s options.', 'woocommerce' ); ?>" href="#">[?]</a></label>
|
||||
<input type="number" size="5" name="variable_stock[<?php echo $loop; ?>]" value="<?php if ( isset( $_stock ) ) echo esc_attr( $_stock ); ?>" step="any" />
|
||||
</td>
|
||||
<td> </td>
|
||||
<td>
|
||||
<label><?php _e( 'Allow Backorders?', 'woocommerce' ); ?></label>
|
||||
<select name="variable_backorders[<?php echo $loop; ?>]">
|
||||
<option value="parent" <?php selected( is_null( $_backorders ), true ); ?>><?php _e( 'Same as parent', 'woocommerce' ); ?></option>
|
||||
<?php
|
||||
foreach ( $parent_data['backorder_options'] as $key => $value )
|
||||
echo '<option value="' . esc_attr( $key ) . '" ' . selected( $key === $_backorders, true, false ) . '>' . esc_html( $value ) . '</option>';
|
||||
?></select>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
|
|
|
@ -425,8 +425,8 @@ class WC_Product_Variable extends WC_Product {
|
|||
'weight' => $variation->get_weight() . ' ' . esc_attr( get_option('woocommerce_weight_unit' ) ),
|
||||
'dimensions' => $variation->get_dimensions(),
|
||||
'min_qty' => 1,
|
||||
'max_qty' => $this->backorders_allowed() ? '' : $variation->stock,
|
||||
'backorders_allowed' => $this->backorders_allowed(),
|
||||
'max_qty' => $variation->backorders_allowed() ? '' : $variation->stock,
|
||||
'backorders_allowed' => $variation->backorders_allowed(),
|
||||
'is_in_stock' => $variation->is_in_stock(),
|
||||
'is_downloadable' => $variation->is_downloadable() ,
|
||||
'is_virtual' => $variation->is_virtual(),
|
||||
|
|
|
@ -108,6 +108,10 @@ class WC_Product_Variation extends WC_Product {
|
|||
$this->manage_stock = 'yes';
|
||||
$this->stock = $this->product_custom_fields['_stock'][0];
|
||||
}
|
||||
|
||||
if ( isset( $this->product_custom_fields['_backorders'][0] ) && ! is_null( $this->product_custom_fields['_backorders'][0] ) ) {
|
||||
$this->backorders = $this->product_custom_fields['_backorders'][0];
|
||||
}
|
||||
|
||||
if ( isset( $this->product_custom_fields['_weight'][0] ) && $this->product_custom_fields['_weight'][0] !== '' ) {
|
||||
$this->variation_has_weight = true;
|
||||
|
|
Loading…
Reference in New Issue