Skip to content
Open
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
27 changes: 21 additions & 6 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public function __construct() {
// add custom taxonomy for Product Sets
add_filter( 'gettext', array( $this, 'change_custom_taxonomy_tip' ), 20, 2 );
add_action( 'wp_ajax_sync_facebook_attributes', array( $this, 'ajax_sync_facebook_attributes' ) );

// automatically sync product attributes when a product is 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 );
}

/**
Expand Down Expand Up @@ -1304,12 +1309,12 @@ public function add_product_settings_tab_content() {
<?php
woocommerce_wp_text_input(
array(
'id' => \WC_Facebook_Product::FB_MPN,
'name' => \WC_Facebook_Product::FB_MPN,
'label' => __( 'Manufacturer Part Number (MPN)', 'facebook-for-woocommerce' ),
'value' => $fb_mpn,
'class' => 'enable-if-sync-enabled',
'desc_tip' => true,
'id' => \WC_Facebook_Product::FB_MPN,
'name' => \WC_Facebook_Product::FB_MPN,
'label' => __( 'Manufacturer Part Number (MPN)', 'facebook-for-woocommerce' ),
'value' => $fb_mpn,
'class' => 'enable-if-sync-enabled',
'desc_tip' => true,
'description' => __( 'Manufacturer Part Number (MPN) of the item', 'facebook-for-woocommerce' ),
)
);
Expand Down Expand Up @@ -1928,6 +1933,16 @@ public function sync_product_attributes( $product_id ) {
}
}

// 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 ) );
}
}

return $facebook_fields;
}

Expand Down