Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions

DefaultFreeExtensions::with_core_profiler_fields()public staticWC 1.0

Decorate plugin data with core profiler fields.

  • Updated description for the core-profiler.
  • Adds learn_more_link and label.
  • Adds install_priority, which is used to sort the plugins. The value is determined by the plugin size. Lower = smaller.

Метод класса: DefaultFreeExtensions{}

Хуков нет.

Возвращает

Массив.

Использование

$result = DefaultFreeExtensions::with_core_profiler_fields( $plugins );
$plugins(массив) (обязательный)
Array of plugins.

Код DefaultFreeExtensions::with_core_profiler_fields() WC 9.3.3

public static function with_core_profiler_fields( array $plugins ) {
	$_plugins = array(
		'woocommerce-payments'          => array(
			'label'            => __( 'Get paid with WooPayments', 'woocommerce' ),
			'image_url'        => plugins_url( '/assets/images/core-profiler/logo-woo.svg', WC_PLUGIN_FILE ),
			'description'      => __( "Securely accept payments and manage payment activity straight from your store's dashboard", 'woocommerce' ),
			'learn_more_link'  => 'https://woocommerce.com/products/woocommerce-payments?utm_source=storeprofiler&utm_medium=product&utm_campaign=freefeatures',
			'install_priority' => 5,
		),
		'woocommerce-services:shipping' => array(
			'label'            => __( 'Print shipping labels with WooCommerce Shipping', 'woocommerce' ),
			'image_url'        => plugins_url( '/assets/images/core-profiler/logo-woo.svg', WC_PLUGIN_FILE ),
			'description'      => __( 'Print USPS and DHL labels directly from your dashboard and save on shipping.', 'woocommerce' ),
			'learn_more_link'  => 'https://woocommerce.com/woocommerce-shipping?utm_source=storeprofiler&utm_medium=product&utm_campaign=freefeatures',
			'install_priority' => 3,
		),
		'jetpack'                       => array(
			'label'            => __( 'Boost content creation with Jetpack AI Assistant', 'woocommerce' ),
			'image_url'        => plugins_url( '/assets/images/core-profiler/logo-jetpack.svg', WC_PLUGIN_FILE ),
			'description'      => __( 'Save time on content creation — unlock high-quality blog posts and pages using AI.', 'woocommerce' ),
			'learn_more_link'  => 'https://woocommerce.com/products/jetpack?utm_source=storeprofiler&utm_medium=product&utm_campaign=freefeatures',
			'install_priority' => 8,
		),
		'pinterest-for-woocommerce'     => array(
			'label'            => __( 'Showcase your products with Pinterest', 'woocommerce' ),
			'image_url'        => plugins_url( '/assets/images/core-profiler/logo-pinterest.svg', WC_PLUGIN_FILE ),
			'description'      => __( 'Get your products in front of a highly engaged audience.', 'woocommerce' ),
			'learn_more_link'  => 'https://woocommerce.com/products/pinterest-for-woocommerce?utm_source=storeprofiler&utm_medium=product&utm_campaign=freefeatures',
			'install_priority' => 2,
		),
		'mailpoet'                      => array(
			'label'            => __( 'Reach your customers with MailPoet', 'woocommerce' ),
			'image_url'        => plugins_url( '/assets/images/core-profiler/logo-mailpoet.svg', WC_PLUGIN_FILE ),
			'description'      => __( 'Send purchase follow-up emails, newsletters, and promotional campaigns.', 'woocommerce' ),
			'learn_more_link'  => 'https://woocommerce.com/products/mailpoet?utm_source=storeprofiler&utm_medium=product&utm_campaign=freefeatures',
			'install_priority' => 7,
		),
		'tiktok-for-business'           => array(
			'label'            => __( 'Create ad campaigns with TikTok', 'woocommerce' ),
			'image_url'        => plugins_url( '/assets/images/core-profiler/logo-tiktok.png', WC_PLUGIN_FILE ),
			'description'      => __( 'Create advertising campaigns and reach one billion global users.', 'woocommerce' ),
			'learn_more_link'  => 'https://woocommerce.com/products/tiktok-for-woocommerce?utm_source=storeprofiler&utm_medium=product&utm_campaign=freefeatures',
			'install_priority' => 1,
		),
		'google-listings-and-ads'       => array(
			'label'            => __( 'Drive sales with Google for WooCommerce', 'woocommerce' ),
			'image_url'        => plugins_url( '/assets/images/core-profiler/logo-google.svg', WC_PLUGIN_FILE ),
			'description'      => __( 'Reach millions of active shoppers across Google with free product listings and ads.', 'woocommerce' ),
			'learn_more_link'  => 'https://woocommerce.com/products/google-listings-and-ads?utm_source=storeprofiler&utm_medium=product&utm_campaign=freefeatures',
			'install_priority' => 6,
		),
		'woocommerce-services:tax'      => array(
			'label'            => __( 'Get automated tax rates with WooCommerce Tax', 'woocommerce' ),
			'image_url'        => plugins_url( '/assets/images/core-profiler/logo-woo.svg', WC_PLUGIN_FILE ),
			'description'      => __( 'Automatically calculate how much sales tax should be collected – by city, country, or state.', 'woocommerce' ),
			'learn_more_link'  => 'https://woocommerce.com/products/tax?utm_source=storeprofiler&utm_medium=product&utm_campaign=freefeatures',
			'install_priority' => 4,
		),
	);

	/*
	 * Overwrite the is_visible conditions to just the country restriction
	 * and the requirement for WooCommerce Shipping and WooCommerce Tax
	 * to not be active.
	 */
	$_plugins['woocommerce-services:shipping']['is_visible'] = array(
		array(
			'type'      => 'base_location_country',
			'value'     => 'US',
			'operation' => '=',
		),
		array(
			'type'    => 'not',
			'operand' => array(
				array(
					'type'    => 'plugins_activated',
					'plugins' => array( 'woocommerce-shipping' ),
				),
			),
		),
		array(
			'type'    => 'not',
			'operand' => array(
				array(
					'type'    => 'plugins_activated',
					'plugins' => array( 'woocommerce-tax' ),
				),
			),
		),
	);

	$_plugins['woocommerce-services:tax']['is_visible'] = array(
		self::get_rules_for_wcservices_tax_countries(),
		array(
			'type'    => 'not',
			'operand' => array(
				array(
					'type'    => 'plugins_activated',
					'plugins' => array( 'woocommerce-shipping' ),
				),
			),
		),
		array(
			'type'    => 'not',
			'operand' => array(
				array(
					'type'    => 'plugins_activated',
					'plugins' => array( 'woocommerce-tax' ),
				),
			),
		),
	);

	$remove_plugins_activated_rule = function ( $is_visible ) {
		$is_visible = array_filter(
			array_map(
				function ( $rule ) {
					if ( is_object( $rule ) || ! isset( $rule['operand'] ) ) {
						return $rule;
					}

					return array_filter(
						$rule['operand'],
						function ( $operand ) {
							return 'plugins_activated' !== $operand['type'];
						}
					);
				},
				$is_visible
			)
		);

		return empty( $is_visible ) ? true : $is_visible;
	};

	foreach ( $plugins as &$plugin ) {
		if ( isset( $_plugins[ $plugin['key'] ] ) ) {
			$plugin = array_merge( $plugin, $_plugins[ $plugin['key'] ] );

			/*
			 * Removes the "not plugins_activated" rules from the "is_visible"
			 * ruleset except for the WooCommerce Services plugin.
			 *
			 * WC Services is a plugin that provides shipping and tax features.
			 * WC Services is sometimes labelled as "WooCommerce Shipping" or
			 * "WooCommerce Tax", depending on which functionality of the plugin
			 * is advertised.
			 *
			 * We have two new upcoming, standalone plugins: "WooCommerce Shipping" and
			 * "WooCommerce Tax" (same names as sometimes used for WC Services).
			 * The new plugins are incompatible with the old WC Services plugin.
			 * In order to prevent merchants from running into this plugin conflict,
			 * we want to keep the "not plugins_activated" rules for recommending
			 * WC Services.
			 *
			 * If WC Services and the new plugins are installed together,
			 * a notice is displayed and the plugin functionality is not registered
			 * by either WC Services or WC Shipping and WC Tax.
			 */
			if (
				isset( $plugin['is_visible'] ) &&
				is_array( $plugin['is_visible'] ) &&
				! in_array( $plugin['key'], array( 'woocommerce-services:shipping', 'woocommerce-services:tax' ), true )
			) {
				$plugin['is_visible'] = $remove_plugins_activated_rule( $plugin['is_visible'] );
			}
		}
	}

	return $plugins;
}