Skip to content

Add automatic product attribute synchronization with Facebook#3055

Open
devbodaghe wants to merge 2 commits intofacebook:mainfrom
devbodaghe:fix/auto-sync-product-attributes
Open

Add automatic product attribute synchronization with Facebook#3055
devbodaghe wants to merge 2 commits intofacebook:mainfrom
devbodaghe:fix/auto-sync-product-attributes

Conversation

@devbodaghe
Copy link
Copy Markdown
Contributor

Automatic Product Attribute Synchronization with Facebook

Problem

When product attributes are updated in WooCommerce, they are not automatically synchronized to Facebook. This results in discrepancies between product data on your WooCommerce store and Facebook Shop, as the Facebook integration continues to use outdated attribute values.

Solution

This PR adds automatic synchronization of product attributes with Facebook when they are updated in WooCommerce, ensuring that attribute changes are properly reflected in the Facebook Shop.

Changes Made:

  • Added hooks to automatically trigger the attribute synchronization process when products are updated:

    add_action('woocommerce_update_product', array($this, 'sync_product_attributes'), 10, 1);
    add_action('woocommerce_update_product_variation', array($this, 'sync_product_attributes'), 10, 1);
    add_action('woocommerce_process_product_meta', array($this, 'sync_product_attributes'), 10, 1);
  • Enhanced the sync_product_attributes() method to automatically queue the product for update on Facebook after syncing attributes:

    // After syncing the attributes, update the product on Facebook if we're connected
    $plugin = facebook_for_woocommerce();
    if ($plugin->get_connection_handler()->is_connected() && $plugin->get_integration()->get_product_catalog_id()) {
        // Determine if this is a product we should send to Facebook
        if ('yes' !== get_post_meta($product_id, \WC_Facebook_Product::FB_REMOVE_FROM_SYNC, true)) {
            // Queue the product for sync with Facebook
            facebook_for_woocommerce()->get_products_sync_handler()->create_or_update_products(array($product_id));
        }
    }

Testing

To test this fix:

  1. Edit product attributes in WooCommerce (e.g., color, size, material)
  2. Verify that these changes are properly reflected in the Facebook Shop after the automatic synchronization

Benefits

  • Eliminates manual intervention required to keep product attributes in sync
  • Ensures consistency between your WooCommerce store and Facebook Shop
  • Improves customer experience by displaying accurate product information on Facebook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants