From 02e1d964796b14cd45c4a217806f8b63af0fbb3b Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Sun, 25 May 2025 14:20:52 +0100 Subject: [PATCH 1/8] Removing sync to facebook checkbox --- facebook-commerce.php | 26 ------------------- .../Admin/Settings_Screens/Product_Sync.php | 9 ------- includes/Lifecycle.php | 7 ----- includes/ProductSync/ProductValidator.php | 14 ---------- includes/Products/Feed.php | 6 +---- includes/Utilities/Tracker.php | 7 +++-- 6 files changed, 4 insertions(+), 65 deletions(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index 945ad9be0..d3d0e5399 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -74,9 +74,6 @@ class WC_Facebookcommerce_Integration extends WC_Integration { /** @var string the "access token" setting ID */ const SETTING_ACCESS_TOKEN = 'access_token'; - /** @var string the "enable product sync" setting ID */ - const SETTING_ENABLE_PRODUCT_SYNC = 'wc_facebook_enable_product_sync'; - /** @var string the excluded product category IDs setting ID */ const SETTING_EXCLUDED_PRODUCT_CATEGORY_IDS = 'wc_facebook_excluded_product_category_ids'; @@ -2158,11 +2155,6 @@ private function sync_facebook_products() { * @throws PluginException If the plugin is not configured or the Catalog ID is missing. */ private function sync_facebook_products_using_background_processor() { - if ( ! $this->is_product_sync_enabled() ) { - WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Sync to Facebook is disabled' ); - throw new PluginException( __( 'Product sync is disabled.', 'facebook-for-woocommerce' ) ); - } - if ( ! $this->is_configured() || ! $this->get_product_catalog_id() ) { WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( sprintf( 'Not syncing, the plugin is not configured or the Catalog ID is missing' ) ); throw new PluginException( __( 'The plugin is not configured or the Catalog ID is missing.', 'facebook-for-woocommerce' ) ); @@ -2623,24 +2615,6 @@ public function is_advanced_matching_enabled() { return (bool) apply_filters( 'wc_facebook_is_advanced_matching_enabled', true, $this ); } - /** - * Determines whether product sync is enabled. - * - * @return bool - * @since 1.10.0 - */ - public function is_product_sync_enabled() { - /** - * Filters whether product sync is enabled. - * - * @param bool $is_enabled whether product sync is enabled - * @param \WC_Facebookcommerce_Integration $integration the integration instance - * - * @since 1.10.0 - */ - return (bool) apply_filters( 'wc_facebook_is_product_sync_enabled', 'yes' === get_option( self::SETTING_ENABLE_PRODUCT_SYNC, 'yes' ), $this ); - } - /** * Return true if (legacy) feed generation is enabled. * diff --git a/includes/Admin/Settings_Screens/Product_Sync.php b/includes/Admin/Settings_Screens/Product_Sync.php index 2d62cab7a..e4f68b040 100644 --- a/includes/Admin/Settings_Screens/Product_Sync.php +++ b/includes/Admin/Settings_Screens/Product_Sync.php @@ -269,15 +269,6 @@ public function get_settings(): array { 'type' => 'product_sync_title', 'title' => __( 'Product sync', 'facebook-for-woocommerce' ), ), - array( - 'id' => \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, - 'title' => __( 'Enable product sync', 'facebook-for-woocommerce' ), - 'type' => 'checkbox', - 'label' => ' ', - 'default' => 'yes', - 'desc_tip' => __( 'Enable product syncing with Facebook.', 'facebook-for-woocommerce' ), - ), - array( 'id' => \WC_Facebookcommerce_Integration::SETTING_EXCLUDED_PRODUCT_CATEGORY_IDS, 'title' => __( 'Exclude categories from sync', 'facebook-for-woocommerce' ), diff --git a/includes/Lifecycle.php b/includes/Lifecycle.php index e3e23d1a7..895ce977b 100644 --- a/includes/Lifecycle.php +++ b/includes/Lifecycle.php @@ -144,12 +144,6 @@ private function migrate_1_9_settings() { } } - // migrate settings from standalone options - if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] ) ) { - $product_sync_enabled = empty( get_option( 'fb_disable_sync_on_dev_environment', 0 ) ); - $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] = $product_sync_enabled ? 'yes' : 'no'; - } - if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_SCHEDULED_RESYNC_OFFSET ] ) ) { $autosync_time = get_option( 'woocommerce_fb_autosync_time' ); $parsed_time = ! empty( $autosync_time ) ? strtotime( $autosync_time ) : false; @@ -214,7 +208,6 @@ protected function upgrade_to_2_0_0() { $settings_map = array( 'facebook_pixel_id' => \WC_Facebookcommerce_Integration::SETTING_FACEBOOK_PIXEL_ID, 'facebook_page_id' => \WC_Facebookcommerce_Integration::SETTING_FACEBOOK_PAGE_ID, - 'enable_product_sync' => \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, 'excluded_product_category_ids' => \WC_Facebookcommerce_Integration::SETTING_EXCLUDED_PRODUCT_CATEGORY_IDS, 'excluded_product_tag_ids' => \WC_Facebookcommerce_Integration::SETTING_EXCLUDED_PRODUCT_TAG_IDS, 'enable_messenger' => self::SETTING_ENABLE_MESSENGER, diff --git a/includes/ProductSync/ProductValidator.php b/includes/ProductSync/ProductValidator.php index 7c1a929f5..76563d4d8 100644 --- a/includes/ProductSync/ProductValidator.php +++ b/includes/ProductSync/ProductValidator.php @@ -117,7 +117,6 @@ public function __get( $key ) { * @throws ProductExcludedException If product should not be synced. */ public function validate() { - $this->validate_sync_enabled_globally(); $this->validate_product_sync_field(); $this->validate_product_status(); $this->validate_product_visibility(); @@ -132,7 +131,6 @@ public function validate() { * @throws ProductExcludedException If product should not be synced. */ public function validate_but_skip_status_check() { - $this->validate_sync_enabled_globally(); $this->validate_product_sync_field(); $this->validate_product_visibility(); $this->validate_product_terms(); @@ -145,7 +143,6 @@ public function validate_but_skip_status_check() { * @throws ProductExcludedException|ProductInvalidException If product should not be synced. */ public function validate_but_skip_sync_field() { - $this->validate_sync_enabled_globally(); $this->validate_product_visibility(); $this->validate_product_terms(); } @@ -218,17 +215,6 @@ public function passes_all_checks_except_sync_field(): bool { return true; } - /** - * Check whether product sync is globally disabled. - * - * @throws ProductExcludedException If product should not be synced. - */ - protected function validate_sync_enabled_globally() { - if ( ! $this->integration->is_product_sync_enabled() ) { - throw new ProductExcludedException( __( 'Product sync is globally disabled.', 'facebook-for-woocommerce' ) ); - } - } - /** * Check whether the product's status excludes it from sync. * diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index e18ab1349..8d0f80b7e 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -168,11 +168,9 @@ public function schedule_feed_generation() { set_transient( $flag_name, 'yes', HOUR_IN_SECONDS ); $integration = facebook_for_woocommerce()->get_integration(); $configured_ok = $integration && $integration->is_configured(); - // Only schedule feed job if store has not opted out of product sync. - $store_allows_sync = $configured_ok && $integration->is_product_sync_enabled(); // Only schedule if has not opted out of feed generation (e.g. large stores). $store_allows_feed = $configured_ok && $integration->is_legacy_feed_file_generation_enabled(); - if ( ! $store_allows_sync || ! $store_allows_feed ) { + if (! $store_allows_feed ) { as_unschedule_all_actions( self::GENERATE_FEED_ACTION ); $message = ''; @@ -180,8 +178,6 @@ public function schedule_feed_generation() { $message = 'Integration not configured.'; } elseif ( ! $store_allows_feed ) { $message = 'Store does not allow feed.'; - } elseif ( ! $store_allows_sync ) { - $message = 'Store does not allow sync.'; } WC_Facebookcommerce_Utils::log_to_meta( sprintf( 'Product feed scheduling failed: %s', $message ), diff --git a/includes/Utilities/Tracker.php b/includes/Utilities/Tracker.php index 95ee506cf..b4a3e6a7e 100644 --- a/includes/Utilities/Tracker.php +++ b/includes/Utilities/Tracker.php @@ -114,12 +114,11 @@ public function add_tracker_data( array $data = [] ) { $data['extensions']['facebook-for-woocommerce']['is-connected'] = wc_bool_to_string( $connection_is_happy ); /** - * What features are enabled on this site? + * Sync will always be allowed post WooAllProducts * - * @since 2.3.4 + * @since 3.4.12 */ - $product_sync_enabled = facebook_for_woocommerce()->get_integration()->is_product_sync_enabled(); - $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = wc_bool_to_string( $product_sync_enabled ); + $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = true; /** * How long did the last feed generation take (or did it fail - 0)? This counts just the time when the batches have been generated. From 8201a1022ad52ce5b5d9e7afe5957af5784764bb Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Mon, 26 May 2025 11:02:49 +0100 Subject: [PATCH 2/8] Adding tags to all the products previously hidden by syn all chekbox --- includes/fbproduct.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/fbproduct.php b/includes/fbproduct.php index 118bba5ed..b84566e49 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -1780,6 +1780,24 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel } } + /** + * If code has reached this point of execution + * Means that sync validations have been checked. + * Visibility has been set for the products, both for simple and variations + * Now if prevously they had product sync checkbox/ global products sync off, we will mark the products + * This is in accordance with the facet that now all the products will sync + */ + + $global_sync_checkbox_status = 'yes' === get_option('wc_facebook_enable_product_sync', 'yes' ); + if($global_sync_checkbox_status === false){ + /** + * Previously they wouldn't have syned + * But now they are + */ + $product_data["is_woo_all_products_sync"] = true; + } + + if ( self::PRODUCT_PREP_TYPE_ITEMS_BATCH === $type_to_prepare_for ) { $product_data['title'] = Helper::str_truncate( WC_Facebookcommerce_Utils::clean_string( $this->get_title() ), self::MAX_TITLE_LENGTH ); $product_data['image_link'] = $image_urls[0]; From eb9a3b2edf123dc554351f551acceb6be53bb467 Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Mon, 26 May 2025 11:23:21 +0100 Subject: [PATCH 3/8] Fixing Phpcs code --- includes/Products/Feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index 8d0f80b7e..c99393f9e 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -170,7 +170,7 @@ public function schedule_feed_generation() { $configured_ok = $integration && $integration->is_configured(); // Only schedule if has not opted out of feed generation (e.g. large stores). $store_allows_feed = $configured_ok && $integration->is_legacy_feed_file_generation_enabled(); - if (! $store_allows_feed ) { + if ( ! $store_allows_feed ) { as_unschedule_all_actions( self::GENERATE_FEED_ACTION ); $message = ''; From 47ddc627abe17ed645cf855df6ad53b5813aeeaf Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Mon, 26 May 2025 12:28:32 +0100 Subject: [PATCH 4/8] Removing tests that are no longer required --- .../WCFacebookCommerceIntegrationTest.php | 53 ------------------- 1 file changed, 53 deletions(-) diff --git a/tests/Unit/WCFacebookCommerceIntegrationTest.php b/tests/Unit/WCFacebookCommerceIntegrationTest.php index 81685bcba..4b04ccde2 100644 --- a/tests/Unit/WCFacebookCommerceIntegrationTest.php +++ b/tests/Unit/WCFacebookCommerceIntegrationTest.php @@ -2460,59 +2460,6 @@ function ( $is_enabled ) { $this->assertFalse( $output ); } - /** - * Tests is product sync enabled returns default value. - * - * @return void - */ - public function test_is_product_sync_enabled_no_filter_no_option() { - $this->teardown_callback_category_safely( 'wc_facebook_is_product_sync_enabled' ); - delete_option( WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ); - - $result = $this->integration->is_product_sync_enabled(); - - $this->assertTrue( $result ); - } - - /** - * Tests is product sync enabled returns option value. - * - * @return void - */ - public function test_is_product_sync_enabled_no_filter() { - $this->teardown_callback_category_safely( 'wc_facebook_is_product_sync_enabled' ); - add_option( - WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, - 'no' - ); - - $result = $this->integration->is_product_sync_enabled(); - - $this->assertFalse( $result ); - } - - /** - * Tests is product sync enabled with filter. - * - * @return void - */ - public function test_is_product_sync_enabled_with_filter() { - $this->add_filter_with_safe_teardown( - 'wc_facebook_is_product_sync_enabled', - function ( $is_enabled ) { - return false; - } - ); - add_option( - WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, - 'yes' - ); - - $result = $this->integration->is_product_sync_enabled(); - - $this->assertFalse( $result ); - } - /** * Tests is legacy feed file generation enabled with no option set. * From 7a34e75d500eb5a2f581addafc6085ec21212b55 Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 6 Jun 2025 19:50:01 +0100 Subject: [PATCH 5/8] Adding diff comment fixes --- includes/Products/Feed.php | 2 +- includes/Utilities/Tracker.php | 4 ++-- includes/fbproduct.php | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index c99393f9e..92fb04922 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -170,7 +170,7 @@ public function schedule_feed_generation() { $configured_ok = $integration && $integration->is_configured(); // Only schedule if has not opted out of feed generation (e.g. large stores). $store_allows_feed = $configured_ok && $integration->is_legacy_feed_file_generation_enabled(); - if ( ! $store_allows_feed ) { + if ( ! $store_allows_feed || ! $configured_ok) { as_unschedule_all_actions( self::GENERATE_FEED_ACTION ); $message = ''; diff --git a/includes/Utilities/Tracker.php b/includes/Utilities/Tracker.php index b4a3e6a7e..bb9c10657 100644 --- a/includes/Utilities/Tracker.php +++ b/includes/Utilities/Tracker.php @@ -114,9 +114,9 @@ public function add_tracker_data( array $data = [] ) { $data['extensions']['facebook-for-woocommerce']['is-connected'] = wc_bool_to_string( $connection_is_happy ); /** - * Sync will always be allowed post WooAllProducts + * Synchronization will always be permitted once we initiate the process of syncing all WooCommerce products. * - * @since 3.4.12 + * @since 3.5.3 */ $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = true; diff --git a/includes/fbproduct.php b/includes/fbproduct.php index b84566e49..a3b850919 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -1781,15 +1781,13 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel } /** - * If code has reached this point of execution - * Means that sync validations have been checked. * Visibility has been set for the products, both for simple and variations * Now if prevously they had product sync checkbox/ global products sync off, we will mark the products * This is in accordance with the facet that now all the products will sync */ - $global_sync_checkbox_status = 'yes' === get_option('wc_facebook_enable_product_sync', 'yes' ); - if($global_sync_checkbox_status === false){ + $deprecated_global_sync_checkbox_status = 'yes' === get_option('wc_facebook_enable_product_sync', 'yes' ); + if($deprecated_global_sync_checkbox_status === false){ /** * Previously they wouldn't have syned * But now they are From 28dc5da75f8dd78a4c0bcea2eee2f18765827132 Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 6 Jun 2025 19:58:09 +0100 Subject: [PATCH 6/8] Adding phpcs fixes --- includes/Products/Feed.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index 92fb04922..8aa92479d 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -170,7 +170,7 @@ public function schedule_feed_generation() { $configured_ok = $integration && $integration->is_configured(); // Only schedule if has not opted out of feed generation (e.g. large stores). $store_allows_feed = $configured_ok && $integration->is_legacy_feed_file_generation_enabled(); - if ( ! $store_allows_feed || ! $configured_ok) { + if ( ! $store_allows_feed || ! $configured_ok ) { as_unschedule_all_actions( self::GENERATE_FEED_ACTION ); $message = ''; From 8322b916eaf2cede613dc095d9e38f12d2f712eb Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 6 Jun 2025 21:39:09 +0100 Subject: [PATCH 7/8] Adding tagging with ints --- includes/fbproduct.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/fbproduct.php b/includes/fbproduct.php index a3b850919..3d4d0920e 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -1792,7 +1792,7 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel * Previously they wouldn't have syned * But now they are */ - $product_data["is_woo_all_products_sync"] = true; + $product_data["is_woo_all_products_sync"] = 1; } From 29a89922c63c7754ac60ce8bed1c2f6277eb771a Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 6 Jun 2025 21:43:30 +0100 Subject: [PATCH 8/8] Adding comment change --- includes/fbproduct.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/fbproduct.php b/includes/fbproduct.php index 3d4d0920e..6b027b998 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -1783,7 +1783,6 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel /** * Visibility has been set for the products, both for simple and variations * Now if prevously they had product sync checkbox/ global products sync off, we will mark the products - * This is in accordance with the facet that now all the products will sync */ $deprecated_global_sync_checkbox_status = 'yes' === get_option('wc_facebook_enable_product_sync', 'yes' );