From e3744709c7276f752374f33a80d271231b23b362 Mon Sep 17 00:00:00 2001 From: Ilyas Foo Date: Thu, 9 Jun 2022 16:21:28 +0800 Subject: [PATCH] Wrap product spotlight tour under ExPlat logic (#33361) * Add experiment wrap * Changelog * Move experiment check to bottom to minimize explat calls --- .../changelog/add-33162-experiment-logic | 4 ++++ .../admin/class-wc-admin-pointers.php | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 plugins/woocommerce/changelog/add-33162-experiment-logic diff --git a/plugins/woocommerce/changelog/add-33162-experiment-logic b/plugins/woocommerce/changelog/add-33162-experiment-logic new file mode 100644 index 00000000000..00d13cf4579 --- /dev/null +++ b/plugins/woocommerce/changelog/add-33162-experiment-logic @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Wrap spotlight product tour under experiment logic diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-pointers.php b/plugins/woocommerce/includes/admin/class-wc-admin-pointers.php index 2fb2bc3f8ed..b04e1abe6ca 100644 --- a/plugins/woocommerce/includes/admin/class-wc-admin-pointers.php +++ b/plugins/woocommerce/includes/admin/class-wc-admin-pointers.php @@ -42,6 +42,22 @@ class WC_Admin_Pointers { } } + /** + * Check if product tour experiment is treatment. + * + * @return bool + */ + public static function is_experiment_product_tour() { + $anon_id = isset( $_COOKIE['tk_ai'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['tk_ai'] ) ) : ''; + $allow_tracking = 'yes' === get_option( 'woocommerce_allow_tracking' ); + $abtest = new \WooCommerce\Admin\Experimental_Abtest( + $anon_id, + 'woocommerce', + $allow_tracking + ); + return $abtest->get_variation( 'woocommerce_products_tour' ) === 'treatment'; + } + /** * Pointers for creating a product. */ @@ -55,7 +71,8 @@ class WC_Admin_Pointers { if ( Features::is_enabled( 'experimental-product-tour' ) && isset( $_GET['spotlight'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended - isset( $wp_post_types ) + isset( $wp_post_types ) && + self::is_experiment_product_tour() ) { $labels = $wp_post_types['product']->labels; $labels->add_new = __( 'Enable guided mode', 'woocommerce' );