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..8aa92479d 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 || ! $configured_ok ) { 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..bb9c10657 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? + * Synchronization will always be permitted once we initiate the process of syncing all WooCommerce products. * - * @since 2.3.4 + * @since 3.5.3 */ - $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. diff --git a/includes/fbproduct.php b/includes/fbproduct.php index 118bba5ed..6b027b998 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -1780,6 +1780,21 @@ 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 + */ + + $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 + */ + $product_data["is_woo_all_products_sync"] = 1; + } + + 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]; 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. *