plugin = $plugin; $this->should_show_banners(); $this->add_hooks(); } public static function enqueue_assets() { wp_enqueue_script( 'wc-backbone-modal', null, array( 'backbone' ) ); wp_enqueue_script( 'facebook-for-woocommerce-modal', facebook_for_woocommerce()->get_asset_build_dir_url() . '/admin/modal.js', array( 'jquery', 'wc-backbone-modal', 'jquery-blockui' ), \WC_Facebookcommerce::PLUGIN_VERSION ); wp_enqueue_script( 'facebook-for-woocommerce-plugin-update', facebook_for_woocommerce()->get_asset_build_dir_url() . '/admin/plugin-rendering.js', array( 'jquery', 'wc-backbone-modal', 'jquery-blockui', 'jquery-tiptip', 'facebook-for-woocommerce-modal', 'wc-enhanced-select' ), \WC_Facebookcommerce::PLUGIN_VERSION, ); wp_localize_script( 'facebook-for-woocommerce-plugin-update', 'facebook_for_woocommerce_plugin_update', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'set_excluded_terms_prompt_nonce' => wp_create_nonce( 'set-excluded-terms-prompt' ), 'opt_out_of_sync' => wp_create_nonce( self::ACTION_OPT_OUT_OF_SYNC ), 'banner_close' => wp_create_nonce( self::ACTION_CLOSE_BANNER ), 'sync_back_in' => wp_create_nonce( self::ACTION_SYNC_BACK_IN ), 'product_set_banner_closed_nonce' => wp_create_nonce( self::ACTION_PRODUCT_SET_BANNER_CLOSED ), 'sync_in_progress' => Sync::is_sync_in_progress(), 'opt_out_confirmation_message' => self::get_opt_out_modal_message(), 'opt_out_confirmation_buttons' => self::get_opt_out_modal_buttons(), ) ); } private static function add_hooks() { add_action( 'admin_enqueue_scripts', [ __CLASS__, 'enqueue_assets' ] ); add_action( 'wp_ajax_wc_facebook_opt_out_of_sync', [ __CLASS__, 'opt_out_of_sync_clicked' ] ); add_action( 'wp_ajax_nopriv_wc_facebook_opt_out_of_sync', [ __CLASS__,'opt_out_of_sync_clicked' ] ); add_action( 'wp_ajax_wc_banner_close_action', [ __CLASS__, 'reset_upcoming_version_banners' ] ); add_action( 'wp_ajax_nopriv_wc_banner_close_action', [ __CLASS__,'reset_upcoming_version_banners' ] ); add_action( 'wp_ajax_wc_facebook_sync_all_products', [ __CLASS__, 'sync_all_clicked' ] ); add_action( 'wp_ajax_nopriv_wc_facebook_sync_all_products', [ __CLASS__,'sync_all_clicked' ] ); add_action( 'wp_ajax_wc_banner_post_update_close_action', [ __CLASS__, 'reset_plugin_updated_successfully_banner' ] ); add_action( 'wp_ajax_nopriv_wc_banner_post_update_close_action', [ __CLASS__,'reset_plugin_updated_successfully_banner' ] ); add_action( 'wp_ajax_wc_banner_post_update__master_sync_off_close_action', [ __CLASS__, 'reset_plugin_updated_successfully_but_master_sync_off_banner' ] ); add_action( 'wp_ajax_nopriv_wc_banner_post_update__master_sync_off_close_action', [ __CLASS__,'reset_plugin_updated_successfully_but_master_sync_off_banner' ] ); add_action( 'wp_ajax_wc_facebook_product_set_banner_closed', [ __CLASS__, 'product_set_banner_closed' ] ); } public function should_show_banners() { $current_version = $this->plugin->get_version(); $is_rolled_out = $this->plugin->get_rollout_switches()->is_switch_enabled( RolloutSwitches::SWITCH_WOO_ALL_PRODUCTS_SYNC_ENABLED ); /** * Case when current version is less or equal to latest * but latest is below 3.5.1 * Should show the opt in/ opt out banner */ if ( version_compare( $current_version, self::ALL_PRODUCTS_PLUGIN_VERSION, '<' ) ) { if ( get_transient( 'upcoming_woo_all_products_banner_hide' ) ) { return; } add_action( 'admin_notices', [ __CLASS__, 'upcoming_woo_all_products_banner' ], 0, 1 ); } elseif ( version_compare( $current_version, self::ALL_PRODUCTS_PLUGIN_VERSION, '>=' ) && $is_rolled_out ) { add_action( 'admin_notices', [ __CLASS__, 'plugin_updated_banner' ], 0, 1 ); } } public static function get_opt_out_time() { $option_value = get_option( self::MASTER_SYNC_OPT_OUT_TIME ); if ( ! $option_value ) { return ''; } return $option_value; } public static function is_master_sync_on() { $option_value = self::get_opt_out_time(); return '' === $option_value; } public static function upcoming_woo_all_products_banner() { $screen = get_current_screen(); if ( isset( $screen->id ) && 'marketing_page_wc-facebook' === $screen->id ) { echo '
'; echo ''; } } public static function plugin_updated_banner() { $screen = get_current_screen(); if ( isset( $screen->id ) && 'marketing_page_wc-facebook' === $screen->id ) { if ( self::is_master_sync_on() && ! get_transient( 'plugin_updated_banner_hide' ) ) { echo 'As part of this update, all your products automatically sync to Meta. It may take some time before all your products are synced. If you change your mind, go to WooCommerce > Products and select which products to un-sync. About syncing products to Meta
It may take some time before all your products are synced. If you change your mind, go to WooCommerce > Products and select which products to un-sync. About syncing products to Meta
To see all the changes, view the changelog. Since you’ve opted out of automatically syncing all your products, some of your products are not yet on Meta. We recommend turning on auto syncing to help drive your sales and improve ad performance. About syncing products to Meta
If you opt out, we will not be syncing your products to your Meta catalog even after you update your Meta for WooCommerce plugin.
However, we strongly recommend syncing all products to help drive sales and optimize ad performance. Products that aren’t synced will not be available for your customers to discover and buy in your ads and shops.
If you change your mind later, you can easily un-sync your products by going to WooCommerce > Products.
'; } public static function get_opt_out_modal_buttons() { return ' Opt out '; } }