diff --git a/facebook-commerce.php b/facebook-commerce.php index 121f88a34..529d26041 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -87,6 +87,9 @@ class WC_Facebookcommerce_Integration extends WC_Integration { /** @var string the scheduled resync offset setting ID */ const SETTING_SCHEDULED_RESYNC_OFFSET = 'scheduled_resync_offset'; + /** @var string the "meta diagnosis" setting ID */ + const SETTING_ENABLE_META_DIAGNOSIS = 'wc_facebook_enable_meta_diagnosis'; + /** @var string the "debug mode" setting ID */ const SETTING_ENABLE_DEBUG_MODE = 'wc_facebook_enable_debug_mode'; @@ -2741,6 +2744,17 @@ public function is_legacy_feed_file_generation_enabled() { return 'yes' === get_option( self::OPTION_LEGACY_FEED_FILE_GENERATION_ENABLED, 'yes' ); } + /** + * Determines whether meta diagnosis is enabled. + * + * @return bool + * @since 3.4.4 + * + */ + public function is_meta_diagnosis_enabled() { + return (bool) ( 'yes' === get_option( self::SETTING_ENABLE_META_DIAGNOSIS ) ); + } + /** * Determines whether debug mode is enabled. * diff --git a/includes/API.php b/includes/API.php index 2101a41c4..f0acf9c2b 100644 --- a/includes/API.php +++ b/includes/API.php @@ -620,6 +620,9 @@ public function log( $facebook_external_merchant_settings_id, $message, $error ) } public function log_to_meta( $context) { + if(!facebook_for_woocommerce()->get_integration()->is_meta_diagnosis_enabled()) { + return; + } $request = new API\MetaLog\Request( $context ); $this->set_response_handler( API\MetaLog\Response::class ); return $this->perform_request( $request ); diff --git a/includes/Admin/Settings_Screens/Connection.php b/includes/Admin/Settings_Screens/Connection.php index 6e2ce12b8..287b1f186 100644 --- a/includes/Admin/Settings_Screens/Connection.php +++ b/includes/Admin/Settings_Screens/Connection.php @@ -472,6 +472,15 @@ public function get_settings() { 'type' => 'title', ), + array( + 'id' => \WC_Facebookcommerce_Integration::SETTING_ENABLE_META_DIAGNOSIS, + 'title' => __( 'Enable meta diagnosis', 'facebook-for-woocommerce' ), + 'type' => 'checkbox', + 'desc' => __( 'Upload plugin events to Meta', 'facebook-for-woocommerce' ), + 'desc_tip' => sprintf( __( 'Allow Meta to monitor your logs and help fix issues. Personally identifiable information will not be collected.', 'facebook-for-woocommerce' ) ), + 'default' => 'yes', + ), + array( 'id' => \WC_Facebookcommerce_Integration::SETTING_ENABLE_DEBUG_MODE, 'title' => __( 'Enable debug mode', 'facebook-for-woocommerce' ), diff --git a/tests/Unit/Admin/Settings/ConnectionTest.php b/tests/Unit/Admin/Settings/ConnectionTest.php index 18a94e4d2..6fea9433b 100644 --- a/tests/Unit/Admin/Settings/ConnectionTest.php +++ b/tests/Unit/Admin/Settings/ConnectionTest.php @@ -37,14 +37,19 @@ public function testGetSettings(): void { // Check that the settings array has the expected structure $this->assertArrayHasKey('type', $settings[0]); $this->assertEquals('title', $settings[0]['type']); + + // Check meta diagnosis setting + $debug_setting = $settings[1]; + $this->assertEquals('checkbox', $debug_setting['type']); + $this->assertEquals('yes', $debug_setting['default']); // Check debug mode setting - $debug_setting = $settings[1]; + $debug_setting = $settings[2]; $this->assertEquals('checkbox', $debug_setting['type']); $this->assertEquals('no', $debug_setting['default']); // Check feed generator setting - $feed_setting = $settings[2]; + $feed_setting = $settings[3]; $this->assertEquals('checkbox', $feed_setting['type']); $this->assertEquals('no', $feed_setting['default']); }