additional_info ) || ! isset( $wc_pay_spec->additional_info->experiment_version ) ) { return false; } $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 ); $variation_name = $abtest->get_variation( self::EXPLAT_VARIATION_PREFIX . $wc_pay_spec->additional_info->experiment_version ); if ( 'treatment' === $variation_name ) { return true; } return false; } /** * By default, new payment gateways are put at the bottom of the list on the admin "Payments" settings screen. * For visibility, we want WooCommerce Payments to be at the top of the list. * * @param array $ordering Existing ordering of the payment gateways. * * @return array Modified ordering. */ public static function set_gateway_top_of_list( $ordering ) { $ordering = (array) $ordering; $id = WCPaymentGatewayPreInstallWCPayPromotion::GATEWAY_ID; // Only tweak the ordering if the list hasn't been reordered with WooCommerce Payments in it already. if ( ! isset( $ordering[ $id ] ) || ! is_numeric( $ordering[ $id ] ) ) { $is_empty = empty( $ordering ) || empty( $ordering[0] ); $ordering[ $id ] = $is_empty ? 0 : ( min( $ordering ) - 1 ); } return $ordering; } /** * Get WC Pay promotion spec. */ public static function get_wc_pay_promotion_spec() { $promotions = self::get_promotions(); $wc_pay_promotion_spec = array_values( array_filter( $promotions, function( $promotion ) { return isset( $promotion->plugins ) && in_array( 'woocommerce-payments', $promotion->plugins, true ); } ) ); return current( $wc_pay_promotion_spec ); } /** * Go through the specs and run them. */ public static function get_promotions() { $suggestions = array(); $specs = self::get_specs(); foreach ( $specs as $spec ) { $suggestion = EvaluateSuggestion::evaluate( $spec ); $suggestions[] = $suggestion; } return array_values( array_filter( $suggestions, function( $suggestion ) { return ! property_exists( $suggestion, 'is_visible' ) || $suggestion->is_visible; } ) ); } /** * Delete the specs transient. */ public static function delete_specs_transient() { WcPayPromotionDataSourcePoller::get_instance()->delete_specs_transient(); } /** * Get specs or fetch remotely if they don't exist. */ public static function get_specs() { if ( 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) ) { return array(); } return WcPayPromotionDataSourcePoller::get_instance()->get_specs_from_data_sources(); } }