Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - Out of stock stock products in WooCommerce remain listed on Facebook #2278

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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