auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -81,7 +81,7 @@ class Features {
* @return array
*/
public static function get_optional_feature_options() {
$features = [];
$features = array();
foreach ( array_keys( self::$optional_features ) as $optional_feature_key ) {
$feature_class = self::get_feature_class( $optional_feature_key );
@@ -148,7 +148,7 @@ class Features {
public static function get_available_features() {
$features = self::get_features();
$optional_feature_keys = array_keys( self::$optional_features );
$optional_features_unavailable = [];
$optional_features_unavailable = array();
/**
* Filter allowing WooCommerce Admin optional features to be disabled.
@@ -292,22 +292,8 @@ class Features {
return;
}
$rtl = is_rtl() ? '.rtl' : '';
wp_enqueue_style(
'wc-admin-beta-features-tracking-modal',
WCAdminAssets::get_url( "beta-features-tracking-modal/style{$rtl}", 'css' ),
array( 'wp-components' ),
WCAdminAssets::get_file_version( 'css' )
);
wp_enqueue_script(
'wc-admin-beta-features-tracking-modal',
WCAdminAssets::get_url( 'wp-admin-scripts/beta-features-tracking-modal', 'js' ),
array( 'wp-i18n', 'wp-element', WC_ADMIN_APP ),
WCAdminAssets::get_file_version( 'js' ),
true
);
WCAdminAssets::register_style( 'beta-features-tracking-modal', 'style', array( 'wp-components' ) );
WCAdminAssets::register_script( 'wp-admin-scripts', 'beta-features-tracking-modal', array( 'wp-i18n', 'wp-element', WC_ADMIN_APP ) );
}
/**

View File

@@ -0,0 +1,201 @@
<?php
namespace Automattic\WooCommerce\Admin\Features;
use Automattic\WooCommerce\Admin\PageController;
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
use Automattic\WooCommerce\Admin\WCAdminHelper;
/**
* Takes care of Launch Your Store related actions.
*/
class LaunchYourStore {
const BANNER_DISMISS_USER_META_KEY = 'woocommerce_coming_soon_banner_dismissed';
/**
* Constructor.
*/
public function __construct() {
add_action( 'woocommerce_update_options_site-visibility', array( $this, 'save_site_visibility_options' ) );
add_filter( 'woocommerce_admin_shared_settings', array( $this, 'preload_settings' ) );
add_action( 'wp_footer', array( $this, 'maybe_add_coming_soon_banner_on_frontend' ) );
add_action( 'init', array( $this, 'register_launch_your_store_user_meta_fields' ) );
add_action( 'wp_login', array( $this, 'reset_woocommerce_coming_soon_banner_dismissed' ), 10, 2 );
}
/**
* Save values submitted from WooCommerce -> Settings -> General.
*
* @return void
*/
public function save_site_visibility_options() {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'woocommerce-settings' ) ) {
return;
}
$options = array(
'woocommerce_coming_soon' => array( 'yes', 'no' ),
'woocommerce_store_pages_only' => array( 'yes', 'no' ),
'woocommerce_private_link' => array( 'yes', 'no' ),
);
$at_least_one_saved = false;
foreach ( $options as $name => $option ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( isset( $_POST[ $name ] ) && in_array( $_POST[ $name ], $option, true ) ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
update_option( $name, wp_unslash( $_POST[ $name ] ) );
$at_least_one_saved = true;
}
}
if ( $at_least_one_saved ) {
wc_admin_record_tracks_event( 'site_visibility_saved' );
}
}
/**
* Preload settings for Site Visibility.
*
* @param array $settings settings array.
*
* @return mixed
*/
public function preload_settings( $settings ) {
if ( ! is_admin() ) {
return $settings;
}
$current_screen = get_current_screen();
$is_setting_page = $current_screen && 'woocommerce_page_wc-settings' === $current_screen->id;
if ( $is_setting_page ) {
// Regnerate the share key if it's not set.
add_option( 'woocommerce_share_key', wp_generate_password( 32, false ) );
$settings['siteVisibilitySettings'] = array(
'shop_permalink' => get_permalink( wc_get_page_id( 'shop' ) ),
'woocommerce_coming_soon' => get_option( 'woocommerce_coming_soon' ),
'woocommerce_store_pages_only' => get_option( 'woocommerce_store_pages_only' ),
'woocommerce_private_link' => get_option( 'woocommerce_private_link' ),
'woocommerce_share_key' => get_option( 'woocommerce_share_key' ),
);
}
return $settings;
}
/**
* User must be an admin or editor.
*
* @return bool
*/
private function is_manager_or_admin() {
// phpcs:ignore
if ( ! current_user_can( 'shop_manager' ) && ! current_user_can( 'administrator' ) ) {
return false;
}
return true;
}
/**
* Add 'coming soon' banner on the frontend when the following conditions met.
*
* - User must be either an admin or store editor (must be logged in).
* - 'woocommerce_coming_soon' option value must be 'yes'
* - The page must not be the Coming soon page itself.
*/
public function maybe_add_coming_soon_banner_on_frontend() {
// Do not show the banner if the site is being previewed.
if ( isset( $_GET['site-preview'] ) ) { // @phpcs:ignore
return false;
}
$current_user_id = get_current_user_id();
if ( ! $current_user_id ) {
return false;
}
if ( get_user_meta( $current_user_id, self::BANNER_DISMISS_USER_META_KEY, true ) === 'yes' ) {
return false;
}
if ( ! $this->is_manager_or_admin() ) {
return false;
}
// 'woocommerce_coming_soon' must be 'yes'
if ( get_option( 'woocommerce_coming_soon', 'no' ) !== 'yes' ) {
return false;
}
$store_pages_only = get_option( 'woocommerce_store_pages_only' ) === 'yes';
if ( $store_pages_only && ! WCAdminHelper::is_store_page() ) {
return false;
}
$link = admin_url( 'admin.php?page=wc-settings&tab=site-visibility' );
$rest_url = rest_url( 'wp/v2/users/' . $current_user_id );
$rest_nonce = wp_create_nonce( 'wp_rest' );
$text = sprintf(
// translators: no need to translate it. It's a link.
__(
"
This page is in \"Coming soon\" mode and is only visible to you and those who have permission. To make it public to everyone,&nbsp;<a href='%s'>change visibility settings</a>
",
'woocommerce'
),
$link
);
// phpcs:ignore
echo "<div id='coming-soon-footer-banner'>$text<a class='coming-soon-footer-banner-dismiss' data-rest-url='$rest_url' data-rest-nonce='$rest_nonce'></a></div>";
}
/**
* Register user meta fields for Launch Your Store.
*/
public function register_launch_your_store_user_meta_fields() {
if ( ! $this->is_manager_or_admin() ) {
return;
}
register_meta(
'user',
'woocommerce_launch_your_store_tour_hidden',
array(
'type' => 'string',
'description' => 'Indicate whether the user has dismissed the site visibility tour on the home screen.',
'single' => true,
'show_in_rest' => true,
)
);
register_meta(
'user',
self::BANNER_DISMISS_USER_META_KEY,
array(
'type' => 'string',
'description' => 'Indicate whether the user has dismissed the coming soon notice or not.',
'single' => true,
'show_in_rest' => true,
)
);
}
/**
* Reset 'woocommerce_coming_soon_banner_dismissed' user meta to 'no'.
*
* Runs when a user logs-in successfully.
*
* @param string $user_login user login.
* @param object $user user object.
*/
public function reset_woocommerce_coming_soon_banner_dismissed( $user_login, $user ) {
$existing_meta = get_user_meta( $user->ID, self::BANNER_DISMISS_USER_META_KEY, true );
if ( 'yes' === $existing_meta ) {
update_user_meta( $user->ID, self::BANNER_DISMISS_USER_META_KEY, 'no' );
}
}
}

View File

@@ -58,7 +58,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Google Listings and Ads',
'description' => __( 'Get in front of shoppers and drive traffic so you can grow your business with Smart Shopping Campaigns and free listings.', 'woocommerce' ),
'url' => "https://woo.com/products/google-listings-and-ads/{$utm_string}",
'url' => "https://woocommerce.com/products/google-listings-and-ads/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/google.svg",
'product' => 'google-listings-and-ads',
@@ -76,7 +76,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Pinterest for WooCommerce',
'description' => __( 'Grow your business on Pinterest! Use this official plugin to allow shoppers to Pin products while browsing your store, track conversions, and advertise on Pinterest.', 'woocommerce' ),
'url' => "https://woo.com/products/pinterest-for-woocommerce/{$utm_string}",
'url' => "https://woocommerce.com/products/pinterest-for-woocommerce/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/pinterest.svg",
'product' => 'pinterest-for-woocommerce',
@@ -94,7 +94,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'TikTok for WooCommerce',
'description' => __( 'Create advertising campaigns and reach one billion global users with TikTok for WooCommerce.', 'woocommerce' ),
'url' => "https://woo.com/products/tiktok-for-woocommerce/{$utm_string}",
'url' => "https://woocommerce.com/products/tiktok-for-woocommerce/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/tiktok.jpg",
'product' => 'tiktok-for-business',
@@ -110,7 +110,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'MailPoet',
'description' => __( 'Create and send purchase follow-up emails, newsletters, and promotional campaigns straight from your dashboard.', 'woocommerce' ),
'url' => "https://woo.com/products/mailpoet/{$utm_string}",
'url' => "https://woocommerce.com/products/mailpoet/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/mailpoet.svg",
'product' => 'mailpoet',
@@ -128,7 +128,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Mailchimp for WooCommerce',
'description' => __( 'Send targeted campaigns, recover abandoned carts and more with Mailchimp.', 'woocommerce' ),
'url' => "https://woo.com/products/mailchimp-for-woocommerce/{$utm_string}",
'url' => "https://woocommerce.com/products/mailchimp-for-woocommerce/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/mailchimp.svg",
'product' => 'mailchimp-for-woocommerce',
@@ -144,7 +144,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Klaviyo for WooCommerce',
'description' => __( 'Grow and retain customers with intelligent, impactful email and SMS marketing automation and a consolidated view of customer interactions.', 'woocommerce' ),
'url' => "https://woo.com/products/klaviyo-for-woocommerce/{$utm_string}",
'url' => "https://woocommerce.com/products/klaviyo-for-woocommerce/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/klaviyo.png",
'product' => 'klaviyo',
@@ -160,7 +160,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'AutomateWoo',
'description' => __( 'Convert and retain customers with automated marketing that does the hard work for you.', 'woocommerce' ),
'url' => "https://woo.com/products/automatewoo/{$utm_string}",
'url' => "https://woocommerce.com/products/automatewoo/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/automatewoo.svg",
'product' => 'automatewoo',
@@ -178,7 +178,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'AutomateWoo Refer a Friend',
'description' => __( 'Boost your organic sales by adding a customer referral program to your WooCommerce store.', 'woocommerce' ),
'url' => "https://woo.com/products/automatewoo-refer-a-friend/{$utm_string}",
'url' => "https://woocommerce.com/products/automatewoo-refer-a-friend/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/automatewoo.svg",
'product' => 'automatewoo-referrals',
@@ -196,7 +196,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'AutomateWoo Birthdays',
'description' => __( 'Delight customers and boost organic sales with a special WooCommerce birthday email (and coupon!) on their special day.', 'woocommerce' ),
'url' => "https://woo.com/products/automatewoo-birthdays/{$utm_string}",
'url' => "https://woocommerce.com/products/automatewoo-birthdays/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/automatewoo.svg",
'product' => 'automatewoo-birthdays',
@@ -214,7 +214,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Trustpilot Reviews',
'description' => __( 'Collect and showcase verified reviews that consumers trust.', 'woocommerce' ),
'url' => "https://woo.com/products/trustpilot-reviews/{$utm_string}",
'url' => "https://woocommerce.com/products/trustpilot-reviews/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/trustpilot.png",
'product' => 'trustpilot-reviews',
@@ -230,7 +230,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Vimeo for WooCommerce',
'description' => __( 'Turn your product images into stunning videos that engage and convert audiences - no video experience required.', 'woocommerce' ),
'url' => "https://woo.com/products/vimeo/{$utm_string}",
'url' => "https://woocommerce.com/products/vimeo/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/vimeo.png",
'product' => 'vimeo',
@@ -246,7 +246,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Jetpack CRM for WooCommerce',
'description' => __( 'Harness data from WooCommerce to grow your business. Manage leads, customers, and segments, through automation, quotes, invoicing, billing, and email marketing. Power up your store with CRM.', 'woocommerce' ),
'url' => "https://woo.com/products/jetpack-crm/{$utm_string}",
'url' => "https://woocommerce.com/products/jetpack-crm/{$utm_string}",
'direct_install' => true,
'icon' => "{$icon_dir_url}/jetpack-crm.svg",
'product' => 'zero-bs-crm',
@@ -262,7 +262,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'WooCommerce Zapier',
'description' => __( 'Integrate your WooCommerce store with 5000+ cloud apps and services today. Trusted by 11,000+ users.', 'woocommerce' ),
'url' => "https://woo.com/products/woocommerce-zapier/{$utm_string}",
'url' => "https://woocommerce.com/products/woocommerce-zapier/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/zapier.png",
'product' => 'woocommerce-zapier',
@@ -278,7 +278,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Salesforce',
'description' => __( 'Sync your website\'s data like contacts, products, and orders over Salesforce CRM with Salesforce Integration for WooCommerce.', 'woocommerce' ),
'url' => "https://woo.com/products/integration-with-salesforce-for-woocommerce/{$utm_string}",
'url' => "https://woocommerce.com/products/integration-with-salesforce-for-woocommerce/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/salesforce.jpg",
'product' => 'integration-with-salesforce',
@@ -294,7 +294,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Personalized Coupons',
'description' => __( 'Generate dynamic personalized coupons for your customers that increase purchase rates.', 'woocommerce' ),
'url' => "https://woo.com/products/automatewoo/{$utm_string}",
'url' => "https://woocommerce.com/products/automatewoo/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/automatewoo-personalized-coupons.svg",
'product' => 'automatewoo',
@@ -308,7 +308,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Smart Coupons',
'description' => __( 'Powerful, "all in one" solution for gift certificates, store credits, discount coupons and vouchers.', 'woocommerce' ),
'url' => "https://woo.com/products/smart-coupons/{$utm_string}",
'url' => "https://woocommerce.com/products/smart-coupons/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/woocommerce-smart-coupons.svg",
'product' => 'woocommerce-smart-coupons',
@@ -322,7 +322,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'URL Coupons',
'description' => __( 'Create a unique URL that applies a discount and optionally adds one or more products to the customer\'s cart.', 'woocommerce' ),
'url' => "https://woo.com/products/url-coupons/{$utm_string}",
'url' => "https://woocommerce.com/products/url-coupons/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/woocommerce-url-coupons.svg",
'product' => 'woocommerce-url-coupons',
@@ -336,7 +336,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'WooCommerce Store Credit',
'description' => __( 'Create "store credit" coupons for customers which are redeemable at checkout.', 'woocommerce' ),
'url' => "https://woo.com/products/store-credit/{$utm_string}",
'url' => "https://woocommerce.com/products/store-credit/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/woocommerce-store-credit.svg",
'product' => 'woocommerce-store-credit',
@@ -350,7 +350,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Free Gift Coupons',
'description' => __( 'Give away a free item to any customer with the coupon code.', 'woocommerce' ),
'url' => "https://woo.com/products/free-gift-coupons/{$utm_string}",
'url' => "https://woocommerce.com/products/free-gift-coupons/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/woocommerce-free-gift-coupons.svg",
'product' => 'woocommerce-free-gift-coupons',
@@ -364,7 +364,7 @@ class DefaultMarketingRecommendations {
array(
'title' => 'Group Coupons',
'description' => __( 'Coupons for groups. Provides the option to have coupons that are restricted to group members or roles. Works with the free Groups plugin.', 'woocommerce' ),
'url' => "https://woo.com/products/group-coupons/{$utm_string}",
'url' => "https://woocommerce.com/products/group-coupons/{$utm_string}",
'direct_install' => false,
'icon' => "{$icon_dir_url}/woocommerce-group-coupons.svg",
'product' => 'woocommerce-group-coupons',

View File

@@ -12,14 +12,14 @@ defined( 'ABSPATH' ) || exit;
*/
class Init extends RemoteSpecsEngine {
/**
* Slug of the category specifying marketing extensions on the Woo.com store.
* Slug of the category specifying marketing extensions on the WooCommerce.com store.
*
* @var string
*/
const MARKETING_EXTENSION_CATEGORY_SLUG = 'marketing';
/**
* Slug of the subcategory specifying marketing channels on the Woo.com store.
* Slug of the subcategory specifying marketing channels on the WooCommerce.com store.
*
* @var string
*/
@@ -81,7 +81,7 @@ class Init extends RemoteSpecsEngine {
}
/**
* Load recommended plugins from Woo.com
* Load recommended plugins from WooCommerce.com
*
* @return array
*/
@@ -113,7 +113,7 @@ class Init extends RemoteSpecsEngine {
}
/**
* Return only the recommended marketing channels from Woo.com.
* Return only the recommended marketing channels from WooCommerce.com.
*
* @return array
*/
@@ -127,7 +127,7 @@ class Init extends RemoteSpecsEngine {
}
/**
* Return all recommended marketing extensions EXCEPT the marketing channels from Woo.com.
* Return all recommended marketing extensions EXCEPT the marketing channels from WooCommerce.com.
*
* @return array
*/

View File

@@ -2,7 +2,7 @@
namespace Automattic\WooCommerce\Admin\Features\MarketingRecommendations;
use Automattic\WooCommerce\Admin\DataSourcePoller;
use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller;
/**
* Specs data source poller class for marketing recommendations.

View File

@@ -123,14 +123,7 @@ class Init {
return;
}
$rtl = is_rtl() ? '.rtl' : '';
wp_enqueue_style(
'wc-admin-navigation-opt-out',
WCAdminAssets::get_url( "navigation-opt-out/style{$rtl}", 'css' ),
array( 'wp-components' ),
WCAdminAssets::get_file_version( 'css' )
);
WCAdminAssets::register_style( 'navigation-opt-out', 'style', array( 'wp-components' ) );
WCAdminAssets::register_script( 'wp-admin-scripts', 'navigation-opt-out', true );
wp_localize_script(
'wc-admin-navigation-opt-out',

View File

@@ -394,11 +394,12 @@ abstract class Task {
* Track task completion if task is viewable.
*/
public function possibly_track_completion() {
if ( ! $this->is_complete() ) {
if ( $this->has_previously_completed() ) {
return;
}
if ( $this->has_previously_completed() ) {
// Expensive check.
if ( ! $this->is_complete() ) {
return;
}

View File

@@ -414,10 +414,14 @@ class TaskList {
public function get_json() {
$this->possibly_track_completion();
$tasks_json = array();
foreach ( $this->tasks as $task ) {
$json = $task->get_json();
if ( $json['canView'] ) {
$tasks_json[] = $json;
// We have no use for hidden lists, it's expensive to compute individual tasks completion.
if ( $this->is_visible() ) {
foreach ( $this->tasks as $task ) {
$json = $task->get_json();
if ( $json['canView'] ) {
$tasks_json[] = $json;
}
}
}

View File

@@ -118,6 +118,7 @@ class TaskLists {
'Tax',
'Shipping',
'Marketing',
'LaunchYourStore',
);
if ( Features::is_enabled( 'core-profiler' ) ) {
@@ -164,6 +165,7 @@ class TaskLists {
),
),
'tasks' => array(
'StoreConnect',
'AdditionalPayments',
'GetMobileApp',
),

View File

@@ -115,6 +115,14 @@ class AdditionalPayments extends Payments {
return $this->can_view_result;
}
/**
* Action URL.
*
* @return string
*/
public function get_action_url() {
return admin_url( 'admin.php?page=wc-admin&task=payments' );
}
/**
* Check if the store has any enabled gateways in other category.

View File

@@ -21,15 +21,31 @@ class CustomizeStore extends Task {
add_action( 'show_admin_bar', array( $this, 'possibly_hide_wp_admin_bar' ) );
// Use "switch_theme" instead of "after_switch_theme" because the latter is fired after the next WP load and we don't want to trigger action when switching theme to TT3 via onboarding theme API.
global $_GET;
$theme_switch_via_cys_ai_loader = isset( $_GET['theme_switch_via_cys_ai_loader'] ) ? 1 === absint( $_GET['theme_switch_via_cys_ai_loader'] ) : false;
if ( ! $theme_switch_via_cys_ai_loader ) {
add_action( 'switch_theme', array( $this, 'mark_task_as_complete' ) );
}
// Hook to remove unwanted UI elements when users are viewing with ?cys-hide-admin-bar=true.
add_action( 'wp_head', array( $this, 'possibly_remove_unwanted_ui_elements' ) );
add_action( 'save_post_wp_global_styles', array( $this, 'mark_task_as_complete' ), 10, 3 );
add_action( 'save_post_wp_template', array( $this, 'mark_task_as_complete' ), 10, 3 );
add_action( 'save_post_wp_template_part', array( $this, 'mark_task_as_complete' ), 10, 3 );
}
/**
* Mark the CYS task as complete whenever the user updates their global styles.
*
* @param int $post_id Post ID.
* @param \WP_Post $post Post object.
* @param bool $update Whether this is an existing post being updated.
*
* @return void
*/
public function mark_task_as_complete( $post_id, $post, $update ) {
if ( $post instanceof \WP_Post ) {
$is_cys_complete = '{"version": 2, "isGlobalStylesUserThemeJSON": true }' !== $post->post_content || in_array( $post->post_type, array( 'wp_template', 'wp_template_part' ), true );
if ( $is_cys_complete ) {
update_option( 'woocommerce_admin_customize_store_completed', 'yes' );
}
}
}
/**
@@ -128,7 +144,7 @@ class CustomizeStore extends Task {
// Default to is-fullscreen-mode to avoid jumps in the UI.
add_filter(
'admin_body_class',
static function( $classes ) {
static function ( $classes ) {
return "$classes is-fullscreen-mode";
}
);
@@ -218,13 +234,6 @@ class CustomizeStore extends Task {
}
}
/**
* Mark task as complete.
*/
public function mark_task_as_complete() {
update_option( 'woocommerce_admin_customize_store_completed', 'yes' );
}
/**
* Appends a small style to hide admin bar
*

View File

@@ -26,7 +26,7 @@ class ExperimentalShippingRecommendation extends Task {
* @return string
*/
public function get_title() {
return __( 'Set up shipping', 'woocommerce' );
return __( 'Get your products shipped', 'woocommerce' );
}
/**

View File

@@ -0,0 +1,124 @@
<?php
namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
/**
* Launch Your Store Task
*/
class LaunchYourStore extends Task {
/**
* Constructor
*
* @param TaskList $task_list Parent task list.
*/
public function __construct( $task_list ) {
parent::__construct( $task_list );
add_action( 'show_admin_bar', array( $this, 'possibly_hide_wp_admin_bar' ) );
}
/**
* ID.
*
* @return string
*/
public function get_id() {
return 'launch-your-store';
}
/**
* Title.
*
* @return string
*/
public function get_title() {
return __( 'Launch your store', 'woocommerce' );
}
/**
* Content.
*
* @return string
*/
public function get_content() {
return __(
"It's time to celebrate you're ready to launch your store! Woo! Hit the button to preview your store and make it public.",
'woocommerce'
);
}
/**
* Time.
*
* @return string
*/
public function get_time() {
return '';
}
/**
* Action URL.
*
* @return string
*/
public function get_action_url() {
return admin_url( 'wp-admin/admin.php?page=wc-admin&path=%2Flaunch-your-store' );
}
/**
* Task completion.
*
* @return bool
*/
public function is_complete() {
return 'yes' !== get_option( 'woocommerce_coming_soon' );
}
/**
* Task visibility.
*
* @return bool
*/
public function can_view() {
return Features::is_enabled( 'launch-your-store' );
}
/**
* Hide the WP admin bar when the user is previewing the site.
*
* @param bool $show Whether to show the admin bar.
*/
public function possibly_hide_wp_admin_bar( $show ) {
if ( isset( $_GET['site-preview'] ) ) { // @phpcs:ignore
return false;
}
global $wp;
$http_referer = wp_get_referer() ?? '';
$parsed_url = wp_parse_url( $http_referer, PHP_URL_QUERY );
$query_string = is_string( $parsed_url ) ? $parsed_url : '';
// Check if the user is coming from the site preview link.
if ( strpos( $query_string, 'site-preview' ) !== false ) {
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
return $show;
}
// Redirect to the current URL with the site-preview query string.
$current_url =
add_query_arg(
array(
'site-preview' => 1,
),
esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) )
);
wp_safe_redirect( $current_url );
exit;
}
return $show;
}
}

View File

@@ -10,6 +10,13 @@ use Automattic\WooCommerce\Internal\Admin\RemoteFreeExtensions\Init as RemoteFre
* Marketing Task
*/
class Marketing extends Task {
/**
* Used to cache is_complete() method result.
*
* @var null
*/
private $is_complete_result = null;
/**
* ID.
*
@@ -25,13 +32,7 @@ class Marketing extends Task {
* @return string
*/
public function get_title() {
if ( true === $this->get_parent_option( 'use_completed_title' ) ) {
if ( $this->is_complete() ) {
return __( 'You added sales channels', 'woocommerce' );
}
return __( 'Get more sales', 'woocommerce' );
}
return __( 'Set up marketing tools', 'woocommerce' );
return __( 'Grow your business', 'woocommerce' );
}
/**
@@ -61,7 +62,11 @@ class Marketing extends Task {
* @return bool
*/
public function is_complete() {
return self::has_installed_extensions();
if ( null === $this->is_complete_result ) {
$this->is_complete_result = self::has_installed_extensions();
}
return $this->is_complete_result;
}
/**

View File

@@ -4,6 +4,7 @@ namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
use Automattic\WooCommerce\Admin\Features\Features;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
use Automattic\WooCommerce\Internal\Admin\WcPayWelcomePage;
/**
* Payments Task
@@ -12,6 +13,7 @@ class Payments extends Task {
/**
* Used to cache is_complete() method result.
*
* @var null
*/
private $is_complete_result = null;
@@ -31,13 +33,7 @@ class Payments extends Task {
* @return string
*/
public function get_title() {
if ( true === $this->get_parent_option( 'use_completed_title' ) ) {
if ( $this->is_complete() ) {
return __( 'You set up payments', 'woocommerce' );
}
return __( 'Set up payments', 'woocommerce' );
}
return __( 'Set up payments', 'woocommerce' );
return __( 'Get paid', 'woocommerce' );
}
/**
@@ -100,4 +96,30 @@ class Payments extends Task {
return ! empty( $enabled_gateways );
}
/**
* Action URL.
*
* @return string
*/
public function get_action_url() {
// Check if the WooPayments plugin is active and the store is supported.
if ( WooCommercePayments::is_supported() && WooCommercePayments::is_wcpay_active() ) {
// If WooPayments is connected, point to the WooPayments overview page.
if ( WooCommercePayments::is_connected() ) {
return add_query_arg( 'from', 'WCADMIN_PAYMENT_TASK', admin_url( 'admin.php?page=wc-admin&path=/payments/overview' ) );
}
// Point to the WooPayments Connect page.
return add_query_arg( 'from', 'WCADMIN_PAYMENT_TASK', admin_url( 'admin.php?page=wc-admin&path=/payments/connect' ) );
}
// Check if there is an active WooPayments incentive via the welcome page.
if ( WcPayWelcomePage::instance()->must_be_visible() ) {
// Point to the WooPayments welcome page.
return add_query_arg( 'from', 'WCADMIN_PAYMENT_TASK', admin_url( 'admin.php?page=wc-admin&path=/wc-pay-welcome-page' ) );
}
return admin_url( 'admin.php?page=wc-admin&task=payments' );
}
}

View File

@@ -9,6 +9,7 @@ use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
* Products Task
*/
class Products extends Task {
const PRODUCT_COUNT_TRANSIENT_NAME = 'woocommerce_product_task_product_count_transient';
/**
* Constructor
@@ -20,6 +21,11 @@ class Products extends Task {
add_action( 'admin_enqueue_scripts', array( $this, 'possibly_add_manual_return_notice_script' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'possibly_add_import_return_notice_script' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'possibly_add_load_sample_return_notice_script' ) );
add_action( 'woocommerce_update_product', array( $this, 'delete_product_count_cache' ) );
add_action( 'woocommerce_new_product', array( $this, 'delete_product_count_cache' ) );
add_action( 'wp_trash_post', array( $this, 'delete_product_count_cache' ) );
add_action( 'untrashed_post', array( $this, 'delete_product_count_cache' ) );
}
/**
@@ -37,13 +43,7 @@ class Products extends Task {
* @return string
*/
public function get_title() {
if ( $this->get_parent_option( 'use_completed_title' ) === true ) {
if ( $this->is_complete() ) {
return __( 'You added products', 'woocommerce' );
}
return __( 'Add products', 'woocommerce' );
}
return __( 'Add my products', 'woocommerce' );
return __( 'Add your products', 'woocommerce' );
}
/**
@@ -77,7 +77,7 @@ class Products extends Task {
}
/**
* Addtional data.
* Additional data.
*
* @return array
*/
@@ -156,12 +156,56 @@ class Products extends Task {
}
/**
* Check if the store has any published products.
* Delete the product count transient used in has_products() method to refresh the cache.
*
* @return void
*/
public static function delete_product_count_cache() {
delete_transient( self::PRODUCT_COUNT_TRANSIENT_NAME );
}
/**
* Check if the store has any user created published products.
*
* @return bool
*/
public static function has_products() {
$counts = wp_count_posts('product');
return isset( $counts->publish ) && $counts->publish > 0;
$product_counts = get_transient( self::PRODUCT_COUNT_TRANSIENT_NAME );
if ( false !== $product_counts && is_numeric( $product_counts ) ) {
return (int) $product_counts > 0;
}
$product_counts = self::count_user_products();
set_transient( self::PRODUCT_COUNT_TRANSIENT_NAME, $product_counts );
return $product_counts > 0;
}
/**
* Count the number of user created products.
* Generated products have the _headstart_post meta key.
*
* @return int The number of user created products.
*/
private static function count_user_products() {
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'fields' => 'ids',
'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
'relation' => 'OR',
array(
'key' => '_headstart_post',
'compare' => 'NOT EXISTS',
),
array(
'key' => '_edit_last',
'compare' => 'EXISTS',
),
),
);
$products_query = new \WP_Query( $args );
return $products_query->found_posts;
}
}

View File

@@ -45,13 +45,7 @@ class Shipping extends Task {
* @return string
*/
public function get_title() {
if ( true === $this->get_parent_option( 'use_completed_title' ) ) {
if ( $this->is_complete() ) {
return __( 'You added shipping costs', 'woocommerce' );
}
return __( 'Add shipping costs', 'woocommerce' );
}
return __( 'Set up shipping', 'woocommerce' );
return __( 'Select your shipping options', 'woocommerce' );
}
/**

View File

@@ -0,0 +1,73 @@
<?php
namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
/**
* Connect store to WooCommerce.com Task
*/
class StoreConnect extends Task {
/**
* ID.
*
* @return string
*/
public function get_id() {
return 'connect-store';
}
/**
* Title.
*
* @return string
*/
public function get_title() {
return __( 'Manage your WooCommerce.com Marketplace subscriptions', 'woocommerce' );
}
/**
* Content.
*
* @return string
*/
public function get_content() {
return '';
}
/**
* Time.
*
* @return string
*/
public function get_time() {
return '';
}
/**
* Task completion.
*
* @return bool
*/
public function is_complete() {
return \WC_Helper::is_site_connected();
}
/**
* Always dismissable.
*
* @return bool
*/
public function is_dismissable() {
return true;
}
/**
* Action URL.
*
* @return string
*/
public function get_action_url() {
return admin_url( 'admin.php?page=wc-admin&tab=my-subscriptions&path=/extensions' );
}
}

View File

@@ -62,13 +62,7 @@ class Tax extends Task {
* @return string
*/
public function get_title() {
if ( $this->get_parent_option( 'use_completed_title' ) === true ) {
if ( $this->is_complete() ) {
return __( 'You added tax rates', 'woocommerce' );
}
return __( 'Add tax rates', 'woocommerce' );
}
return __( 'Set up tax rates', 'woocommerce' );
return __( 'Collect sales tax', 'woocommerce' );
}
/**

View File

@@ -34,7 +34,7 @@ class WooCommercePayments extends Task {
* @return string
*/
public function get_title() {
return __( 'Set up WooPayments', 'woocommerce' );
return __( 'Get paid with WooPayments', 'woocommerce' );
}
/**
@@ -82,18 +82,6 @@ class WooCommercePayments extends Task {
return __( 'Finish setup', 'woocommerce' );
}
/**
* Additional info.
*
* @return string
*/
public function get_additional_info() {
return __(
'Accept credit/debit cards and other popular payment methods with no setup or monthly fees — and manage payments right from your store dashboard.',
'woocommerce'
);
}
/**
* Task completion.
*
@@ -121,7 +109,7 @@ class WooCommercePayments extends Task {
}
/**
* Check if the plugin was requested during onboarding.
* Check if the WooPayments plugin was requested during onboarding.
*
* @return bool
*/
@@ -135,7 +123,7 @@ class WooCommercePayments extends Task {
}
/**
* Check if the plugin is installed.
* Check if the WooPayments plugin is installed.
*
* @return bool
*/
@@ -145,7 +133,16 @@ class WooCommercePayments extends Task {
}
/**
* Check if WooCommerce Payments is connected.
* Check if the WooPayments plugin is active.
*
* @return bool
*/
public static function is_wcpay_active() {
return class_exists( '\WC_Payments' );
}
/**
* Check if WooPayments is connected.
*
* @return bool
*/
@@ -161,7 +158,7 @@ class WooCommercePayments extends Task {
}
/**
* Check if WooCommerce Payments needs setup.
* Check if WooPayments needs setup.
* Errored data or payments not enabled.
*
* @return bool

View File

@@ -57,7 +57,7 @@ class DefaultPaymentGateways {
'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/affirm.png',
'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/affirm.png',
'plugins' => array(),
'external_link' => 'https://woo.com/products/woocommerce-gateway-affirm',
'external_link' => 'https://woocommerce.com/products/woocommerce-gateway-affirm',
'is_visible' => array(
self::get_rules_for_countries(
array(
@@ -718,8 +718,8 @@ class DefaultPaymentGateways {
),
array(
'id' => 'woo-mercado-pago-custom',
'title' => __( 'Mercado Pago Checkout Pro & Custom', 'woocommerce' ),
'content' => __( 'Accept credit and debit cards, offline (cash or bank transfer) and logged-in payments with money in Mercado Pago. Safe and secure payments with the leading payment processor in LATAM.', 'woocommerce' ),
'title' => __( 'Mercado Pago', 'woocommerce' ),
'content' => __( 'Set up your payment methods and accept credit and debit cards, cash, bank transfers and money from your Mercado Pago account. Offer safe and secure payments with Latin Americas leading processor.', 'woocommerce' ),
'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/mercadopago.png',
'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/mercadopago.png',
'plugins' => array( 'woocommerce-mercadopago' ),
@@ -1049,8 +1049,8 @@ class DefaultPaymentGateways {
'klarna_payments',
'amazon_payments_advanced',
),
'BG' => array( 'stripe', 'ppcp-gateway' ),
'HR' => array( 'ppcp-gateway' ),
'BG' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway' ),
'HR' => array( 'woocommerce_payments', 'ppcp-gateway' ),
'CH' => array(
'woocommerce_payments',
'stripe',
@@ -1058,15 +1058,16 @@ class DefaultPaymentGateways {
'mollie_wc_gateway_banktransfer',
'klarna_payments',
),
'CY' => array( 'stripe', 'ppcp-gateway', 'amazon_payments_advanced' ),
'CZ' => array( 'stripe', 'ppcp-gateway' ),
'CY' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway', 'amazon_payments_advanced' ),
'CZ' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway' ),
'DK' => array(
'woocommerce_payments',
'stripe',
'ppcp-gateway',
'klarna_payments',
'amazon_payments_advanced',
),
'EE' => array( 'stripe', 'ppcp-gateway', 'airwallex_main' ),
'EE' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway', 'airwallex_main' ),
'ES' => array(
'woocommerce_payments',
'stripe',
@@ -1077,6 +1078,7 @@ class DefaultPaymentGateways {
'amazon_payments_advanced',
),
'FI' => array(
'woocommerce_payments',
'stripe',
'ppcp-gateway',
'mollie_wc_gateway_banktransfer',
@@ -1112,8 +1114,8 @@ class DefaultPaymentGateways {
'klarna_payments',
'amazon_payments_advanced',
),
'GR' => array( 'stripe', 'ppcp-gateway' ),
'HU' => array( 'stripe', 'ppcp-gateway', 'amazon_payments_advanced' ),
'GR' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway', 'airwallex_main' ),
'HU' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway', 'amazon_payments_advanced' ),
'IE' => array(
'woocommerce_payments',
'stripe',
@@ -1131,10 +1133,10 @@ class DefaultPaymentGateways {
'klarna_payments',
'amazon_payments_advanced',
),
'LV' => array( 'stripe', 'ppcp-gateway' ),
'LT' => array( 'stripe', 'ppcp-gateway' ),
'LU' => array( 'stripe', 'ppcp-gateway', 'amazon_payments_advanced' ),
'MT' => array( 'stripe', 'ppcp-gateway' ),
'LV' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway' ),
'LT' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway' ),
'LU' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway', 'amazon_payments_advanced' ),
'MT' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway' ),
'NL' => array(
'woocommerce_payments',
'stripe',
@@ -1144,7 +1146,7 @@ class DefaultPaymentGateways {
'klarna_payments',
'amazon_payments_advanced',
),
'NO' => array( 'stripe', 'ppcp-gateway', 'kco', 'klarna_payments' ),
'NO' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway', 'kco', 'klarna_payments' ),
'PL' => array(
'woocommerce_payments',
'stripe',
@@ -1157,12 +1159,14 @@ class DefaultPaymentGateways {
'woocommerce_payments',
'stripe',
'ppcp-gateway',
'airwallex_main',
'amazon_payments_advanced',
),
'RO' => array( 'stripe', 'ppcp-gateway' ),
'SK' => array( 'stripe', 'ppcp-gateway' ),
'SL' => array( 'stripe', 'ppcp-gateway', 'amazon_payments_advanced' ),
'RO' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway' ),
'SK' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway' ),
'SL' => array( 'woocommerce_payments', 'stripe', 'ppcp-gateway', 'amazon_payments_advanced' ),
'SE' => array(
'woocommerce_payments',
'stripe',
'ppcp-gateway',
'kco',
@@ -1213,6 +1217,7 @@ class DefaultPaymentGateways {
'payoneer-checkout',
),
'JP' => array(
'woocommerce_payments',
'stripe',
'ppcp-gateway',
'square_credit_card',
@@ -1227,6 +1232,7 @@ class DefaultPaymentGateways {
'ZA' => array( 'payfast', 'paystack' ),
'NG' => array( 'paystack' ),
'GH' => array( 'paystack' ),
'AE' => array( 'woocommerce_payments' ),
);
// If the country code is not in the list, return default priority.

View File

@@ -7,7 +7,7 @@ namespace Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions;
defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\RemoteInboxNotifications\RuleEvaluator;
use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\RuleEvaluator;
/**
* Evaluates the spec and returns the evaluated suggestion.

View File

@@ -18,7 +18,7 @@ class PaymentGatewaySuggestionsDataSourcePoller extends DataSourcePoller {
* Default data sources array.
*/
const DATA_SOURCES = array(
'https://woocommerce.com/wp-json/wccom/payment-gateway-suggestions/1.0/suggestions.json',
'https://woocommerce.com/wp-json/wccom/payment-gateway-suggestions/2.0/suggestions.json',
);
/**

View File

@@ -41,6 +41,7 @@ class BlockRegistry {
'woocommerce/product-text-area-field',
'woocommerce/product-number-field',
'woocommerce/product-linked-list-field',
'woocommerce/product-select-field',
);
/**
@@ -48,6 +49,8 @@ class BlockRegistry {
*/
const PRODUCT_FIELDS_BLOCKS = array(
'woocommerce/product-catalog-visibility-field',
'woocommerce/product-custom-fields',
'woocommerce/product-custom-fields-toggle-field',
'woocommerce/product-description-field',
'woocommerce/product-downloads-field',
'woocommerce/product-images-field',

View File

@@ -10,8 +10,8 @@ use Automattic\WooCommerce\Admin\Features\ProductBlockEditor\ProductTemplate;
use Automattic\WooCommerce\Admin\PageController;
use Automattic\WooCommerce\LayoutTemplates\LayoutTemplateRegistry;
use Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates\SimpleProductTemplate;
use Automattic\WooCommerce\Internal\Admin\Features\ProductBlockEditor\ProductTemplates\ProductVariationTemplate;
use Automattic\WooCommerce\Internal\Features\ProductBlockEditor\ProductTemplates\SimpleProductTemplate;
use Automattic\WooCommerce\Internal\Features\ProductBlockEditor\ProductTemplates\ProductVariationTemplate;
use WP_Block_Editor_Context;
@@ -76,6 +76,9 @@ class Init {
add_action( 'current_screen', array( $this, 'set_current_screen_to_block_editor_if_wc_admin' ) );
add_action( 'rest_api_init', array( $this, 'register_layout_templates' ) );
add_action( 'rest_api_init', array( $this, 'register_user_metas' ) );
add_filter( 'register_block_type_args', array( $this, 'register_metadata_attribute' ) );
// Make sure the block registry is initialized so that core blocks are registered.
BlockRegistry::get_instance();
@@ -112,6 +115,9 @@ class Init {
);
wp_tinymce_inline_scripts();
wp_enqueue_media();
wp_register_style( 'wc-global-presets', false ); // phpcs:ignore
wp_add_inline_style( 'wc-global-presets', wp_get_global_stylesheet( array( 'presets' ) ) );
wp_enqueue_style( 'wc-global-presets' );
}
/**
@@ -379,4 +385,68 @@ class Init {
$this->redirection_controller->set_product_templates( $this->product_templates );
}
/**
* Register user metas.
*/
public function register_user_metas() {
register_rest_field(
'user',
'metaboxhidden_product',
array(
'get_callback' => function ( $object, $attr ) {
$hidden = get_user_meta( $object['id'], $attr, true );
if ( is_array( $hidden ) ) {
// Ensures to always return a string array.
return array_values( $hidden );
}
return array( 'postcustom' );
},
'update_callback' => function ( $value, $object, $attr ) {
// Update the field/meta value.
update_user_meta( $object->ID, $attr, $value );
},
'schema' => array(
'type' => 'array',
'description' => __( 'The metaboxhidden_product meta from the user metas.', 'woocommerce' ),
'items' => array(
'type' => 'string',
),
'arg_options' => array(
'sanitize_callback' => 'wp_parse_list',
'validate_callback' => 'rest_validate_request_arg',
),
),
)
);
}
/**
* Registers the metadata block attribute for all block types.
* This is a fallback/temporary solution until
* the Gutenberg core version registers the metadata attribute.
*
* @see https://github.com/WordPress/gutenberg/blob/6aaa3686ae67adc1a6a6b08096d3312859733e1b/lib/compat/wordpress-6.5/blocks.php#L27-L47
* To do: Remove this method once the Gutenberg core version registers the metadata attribute.
*
* @param array $args Array of arguments for registering a block type.
* @return array $args
*/
public function register_metadata_attribute( $args ) {
// Setup attributes if needed.
if ( ! isset( $args['attributes'] ) || ! is_array( $args['attributes'] ) ) {
$args['attributes'] = array();
}
// Add metadata attribute if it doesn't exist.
if ( ! array_key_exists( 'metadata', $args['attributes'] ) ) {
$args['attributes']['metadata'] = array(
'type' => 'object',
);
}
return $args;
}
}

View File

@@ -61,6 +61,13 @@ class ProductTemplate {
*/
private $icon = null;
/**
* If the template is directly selectable through the UI.
*
* @var boolean
*/
private $is_selectable_by_user = true;
/**
* ProductTemplate constructor
*
@@ -86,6 +93,10 @@ class ProductTemplate {
if ( isset( $data['icon'] ) ) {
$this->icon = $data['icon'];
}
if ( isset( $data['is_selectable_by_user'] ) ) {
$this->is_selectable_by_user = $data['is_selectable_by_user'];
}
}
/**
@@ -180,6 +191,15 @@ class ProductTemplate {
return $this->order;
}
/**
* Get the selectable attribute.
*
* @return boolean Selectable.
*/
public function get_is_selectable_by_user() {
return $this->is_selectable_by_user;
}
/**
* Set the template order.
*
@@ -196,13 +216,14 @@ class ProductTemplate {
*/
public function to_json() {
return array(
'id' => $this->get_id(),
'title' => $this->get_title(),
'description' => $this->get_description(),
'icon' => $this->get_icon(),
'order' => $this->get_order(),
'layoutTemplateId' => $this->get_layout_template_id(),
'productData' => $this->get_product_data(),
'id' => $this->get_id(),
'title' => $this->get_title(),
'description' => $this->get_description(),
'icon' => $this->get_icon(),
'order' => $this->get_order(),
'layoutTemplateId' => $this->get_layout_template_id(),
'productData' => $this->get_product_data(),
'isSelectableByUser' => $this->get_is_selectable_by_user(),
);
}
}

View File

@@ -114,7 +114,7 @@ class DefaultShippingPartners {
'image' => $asset_base_url . 'envia-column.svg',
'features' => $column_layout_features,
),
'learn_more_link' => 'https://woo.com/products/envia-shipping-and-fulfillment/',
'learn_more_link' => 'https://woocommerce.com/products/envia-shipping-and-fulfillment/',
'is_visible' => array(
self::get_rules_for_countries( array( 'CL', 'AR', 'PE', 'BR', 'UY', 'GT' ) ),
),
@@ -157,7 +157,7 @@ class DefaultShippingPartners {
),
),
),
'learn_more_link' => 'https://woo.com/products/easyship-shipping-rates/',
'learn_more_link' => 'https://woocommerce.com/products/easyship-shipping-rates/',
'is_visible' => array(
self::get_rules_for_countries( array( 'SG', 'HK', 'AU', 'NZ' ) ),
),
@@ -282,7 +282,7 @@ class DefaultShippingPartners {
),
),
),
'learn_more_link' => 'https://woo.com/products/shipping/',
'learn_more_link' => 'https://woocommerce.com/products/shipping/',
'is_visible' => array(
self::get_rules_for_countries( array( 'US' ) ),
),

View File

@@ -2,7 +2,7 @@
namespace Automattic\WooCommerce\Admin\Features\ShippingPartnerSuggestions;
use Automattic\WooCommerce\Admin\DataSourcePoller;
use Automattic\WooCommerce\Admin\RemoteSpecs\DataSourcePoller;
/**
* Specs data source poller class for shipping partner suggestions.
@@ -18,7 +18,7 @@ class ShippingPartnerSuggestionsDataSourcePoller extends DataSourcePoller {
* Default data sources array.
*/
const DATA_SOURCES = array(
'https://woocommerce.com/wp-json/wccom/shipping-partner-suggestions/1.0/suggestions.json',
'https://woocommerce.com/wp-json/wccom/shipping-partner-suggestions/2.0/suggestions.json',
);
/**