From c68501f666514e23fb22873eac7a98df94bfbfd2 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 1 Dec 2015 19:14:41 -0200 Subject: [PATCH] [2.4] [API] Fixed backorders edit for variations closes #9618 --- includes/api/class-wc-api-products.php | 6 +++--- includes/api/v2/class-wc-api-products.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/api/class-wc-api-products.php b/includes/api/class-wc-api-products.php index 3d2b3ede58a..551535063e7 100644 --- a/includes/api/class-wc-api-products.php +++ b/includes/api/class-wc-api-products.php @@ -1807,17 +1807,17 @@ class WC_API_Products extends WC_API_Resource { } if ( 'yes' === $managing_stock ) { + $backorders = get_post_meta( $variation_id, '_backorders', true ); + if ( isset( $variation['backorders'] ) ) { if ( 'notify' == $variation['backorders'] ) { $backorders = 'notify'; } else { $backorders = ( true === $variation['backorders'] ) ? 'yes' : 'no'; } - } else { - $backorders = 'no'; } - update_post_meta( $variation_id, '_backorders', $backorders ); + update_post_meta( $variation_id, '_backorders', '' === $backorders ? 'no' : $backorders ); if ( isset( $variation['stock_quantity'] ) ) { wc_update_product_stock( $variation_id, wc_stock_amount( $variation['stock_quantity'] ) ); diff --git a/includes/api/v2/class-wc-api-products.php b/includes/api/v2/class-wc-api-products.php index 4ebaa73a5a1..db18aa71d57 100644 --- a/includes/api/v2/class-wc-api-products.php +++ b/includes/api/v2/class-wc-api-products.php @@ -1349,17 +1349,17 @@ class WC_API_Products extends WC_API_Resource { } if ( 'yes' === $managing_stock ) { + $backorders = get_post_meta( $variation_id, '_backorders', true ); + if ( isset( $variation['backorders'] ) ) { if ( 'notify' == $variation['backorders'] ) { $backorders = 'notify'; } else { $backorders = ( true === $variation['backorders'] ) ? 'yes' : 'no'; } - } else { - $backorders = 'no'; } - update_post_meta( $variation_id, '_backorders', $backorders ); + update_post_meta( $variation_id, '_backorders', '' === $backorders ? 'no' : $backorders ); if ( isset( $variation['stock_quantity'] ) ) { wc_update_product_stock( $variation_id, wc_stock_amount( $variation['stock_quantity'] ) );