plugins[0]; } ); } return $specs; } /** * Checks if promoted gateway can be registered. * * @return boolean if promoted gateway should be registered. */ public static function can_show_promotion() { // Check if WC Pay is enabled. if ( class_exists( '\WC_Payments' ) ) { return false; } if ( 'no' === get_option( 'woocommerce_show_marketplace_suggestions', 'yes' ) ) { return false; } if ( ! apply_filters( 'woocommerce_allow_marketplace_suggestions', true ) ) { return false; } $wc_pay_spec = self::get_wc_pay_promotion_spec(); if ( ! $wc_pay_spec ) { return false; } return true; } /** * 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 ) || ( 1 === count( $ordering ) && false === $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(); } }