Skip to content

Commit

Permalink
Merge pull request #2278 from woocommerce/fix/2277-remove-out-of-stoc…
Browse files Browse the repository at this point in the history
…k-stock-variable-product-on-facebook
  • Loading branch information
rawdreeg authored Aug 26, 2022
2 parents d9ada46 + 8ddb930 commit 0af3714
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions facebook-commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -1053,13 +1053,13 @@ private function delete_fb_product( $product ) {
if ( $variation instanceof \WC_Product ) {
$retailer_ids[] = \WC_Facebookcommerce_Utils::get_fb_retailer_id( $variation );
}
delete_post_meta( $variation_id, self::FB_PRODUCT_ITEM_ID );
}

// enqueue variations to be deleted in the background
facebook_for_woocommerce()->get_products_sync_handler()->delete_products( $retailer_ids );

$this->delete_product_group( $product_id );

} else {

$this->delete_product_item( $product_id );
Expand Down Expand Up @@ -1198,8 +1198,8 @@ public function on_product_publish( $product_id ) {
function delete_on_out_of_stock( $wp_id, $woo_product ) {

if ( Products::product_should_be_deleted( $woo_product ) ) {

$this->delete_product_item( $wp_id );
$product = wc_get_product( $wp_id );
$this->delete_fb_product( $product );
return true;
}

Expand All @@ -1219,11 +1219,11 @@ function on_variable_product_publish( $wp_id, $woo_product = null ) {
$woo_product = new \WC_Facebook_Product( $wp_id );
}

if ( ! $this->product_should_be_synced( $woo_product->woo_product ) ) {
if ( $this->delete_on_out_of_stock( $wp_id, $woo_product->woo_product ) ) {
return;
}

if ( $this->delete_on_out_of_stock( $wp_id, $woo_product->woo_product ) ) {
if ( ! $this->product_should_be_synced( $woo_product->woo_product ) ) {
return;
}

Expand Down Expand Up @@ -1274,11 +1274,11 @@ function on_simple_product_publish( $wp_id, $woo_product = null, &$parent_produc
$woo_product = new \WC_Facebook_Product( $wp_id, $parent_product );
}

if ( ! $this->product_should_be_synced( $woo_product->woo_product ) ) {
if ( $this->delete_on_out_of_stock( $wp_id, $woo_product->woo_product ) ) {
return;
}

if ( $this->delete_on_out_of_stock( $wp_id, $woo_product->woo_product ) ) {
if ( ! $this->product_should_be_synced( $woo_product->woo_product ) ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion includes/Products/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function create_or_update_products( array $product_ids ) {
public function delete_products( array $retailer_ids ) {

foreach ( $retailer_ids as $retailer_id ) {
$this->requests[ $retailer_id ] = self::ACTION_DELETE;
$this->requests[ $this->get_product_index( $retailer_id ) ] = self::ACTION_DELETE;
}
}

Expand Down

0 comments on commit 0af3714

Please sign in to comment.