rebase on oct-10-2023
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce Async Product Editor Category Field.
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\Features\AsyncProductEditorCategoryField;
|
||||
|
||||
use Automattic\Jetpack\Constants;
|
||||
use Automattic\WooCommerce\Admin\Features\Features;
|
||||
use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
|
||||
use Automattic\WooCommerce\Admin\PageController;
|
||||
|
||||
/**
|
||||
* Loads assets related to the async category field for the product editor.
|
||||
*/
|
||||
class Init {
|
||||
|
||||
const FEATURE_ID = 'async-product-editor-category-field';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( Features::is_enabled( self::FEATURE_ID ) ) {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_filter( 'woocommerce_taxonomy_args_product_cat', array( $this, 'add_metabox_args' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds meta_box_cb callback arguments for custom metabox.
|
||||
*
|
||||
* @param array $args Category taxonomy args.
|
||||
* @return array $args category taxonomy args.
|
||||
*/
|
||||
public function add_metabox_args( $args ) {
|
||||
if ( ! isset( $args['meta_box_cb'] ) ) {
|
||||
$args['meta_box_cb'] = 'WC_Meta_Box_Product_Categories::output';
|
||||
$args['meta_box_sanitize_cb'] = 'taxonomy_meta_box_sanitize_cb_checkboxes';
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue scripts needed for the product form block editor.
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
if ( ! PageController::is_embed_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
WCAdminAssets::register_script( 'wp-admin-scripts', 'product-category-metabox', true );
|
||||
wp_localize_script(
|
||||
'wc-admin-product-category-metabox',
|
||||
'wc_product_category_metabox_params',
|
||||
array(
|
||||
'search_categories_nonce' => wp_create_nonce( 'search-categories' ),
|
||||
'search_taxonomy_terms_nonce' => wp_create_nonce( 'search-taxonomy-terms' ),
|
||||
)
|
||||
);
|
||||
wp_enqueue_script( 'product-category-metabox' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue styles needed for the rich text editor.
|
||||
*/
|
||||
public function enqueue_styles() {
|
||||
if ( ! PageController::is_embed_page() ) {
|
||||
return;
|
||||
}
|
||||
$version = Constants::get_constant( 'WC_VERSION' );
|
||||
|
||||
wp_register_style(
|
||||
'woocommerce_admin_product_category_metabox_styles',
|
||||
WCAdminAssets::get_url( 'product-category-metabox/style', 'css' ),
|
||||
array(),
|
||||
$version
|
||||
);
|
||||
wp_style_add_data( 'woocommerce_admin_product_category_metabox_styles', 'rtl', 'replace' );
|
||||
|
||||
wp_enqueue_style( 'woocommerce_admin_product_category_metabox_styles' );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,7 +40,6 @@ class Features {
|
||||
protected static $beta_features = array(
|
||||
'navigation',
|
||||
'new-product-management-experience',
|
||||
'product-block-editor',
|
||||
'settings',
|
||||
);
|
||||
|
||||
|
||||
@@ -21,6 +21,13 @@ class Favorites {
|
||||
*/
|
||||
const META_NAME = 'navigation_favorites';
|
||||
|
||||
/**
|
||||
* Favorites instance.
|
||||
*
|
||||
* @var Favorites|null
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Get class instance.
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,27 @@ class DeprecatedExtendedTask extends Task {
|
||||
*/
|
||||
public $id = '';
|
||||
|
||||
/**
|
||||
* Additional info.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $additional_info = '';
|
||||
|
||||
/**
|
||||
* Content.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $content = '';
|
||||
|
||||
/**
|
||||
* Whether the task is complete or not.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $is_complete = false;
|
||||
|
||||
/**
|
||||
* Snoozeable.
|
||||
*
|
||||
@@ -30,6 +51,35 @@ class DeprecatedExtendedTask extends Task {
|
||||
*/
|
||||
public $is_dismissable = false;
|
||||
|
||||
/**
|
||||
* Whether the store is capable of viewing the task.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $can_view = true;
|
||||
|
||||
/**
|
||||
* Level.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $level = 3;
|
||||
|
||||
/**
|
||||
* Time.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $time;
|
||||
|
||||
/**
|
||||
* Title.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $title = '';
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -76,7 +126,7 @@ class DeprecatedExtendedTask extends Task {
|
||||
}
|
||||
|
||||
/**
|
||||
* Additonal info.
|
||||
* Additional info.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,10 @@ class TaskLists {
|
||||
protected static $default_tasks_loaded = false;
|
||||
|
||||
/**
|
||||
* Array of default tasks.
|
||||
* The contents of this array is used in init_tasks() to run their init() methods.
|
||||
* If the classes do not have an init() method then nothing is executed.
|
||||
* Beyond that, adding tasks to this list has no effect, see init_default_lists() for the list of tasks.
|
||||
* that are added for each task list.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
@@ -108,21 +111,39 @@ class TaskLists {
|
||||
* Initialize default lists.
|
||||
*/
|
||||
public static function init_default_lists() {
|
||||
$tasks = array(
|
||||
'CustomizeStore',
|
||||
'StoreDetails',
|
||||
'Purchase',
|
||||
'Products',
|
||||
'WooCommercePayments',
|
||||
'Payments',
|
||||
'Tax',
|
||||
'Shipping',
|
||||
'Marketing',
|
||||
'Appearance',
|
||||
);
|
||||
|
||||
if ( Features::is_enabled( 'core-profiler' ) ) {
|
||||
$key = array_search( 'StoreDetails', $tasks, true );
|
||||
if ( false !== $key ) {
|
||||
unset( $tasks[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the old Personalize your store task if the new CustomizeStore is enabled.
|
||||
$task_to_remove = Features::is_enabled( 'customize-store' ) ? 'Appearance' : 'CustomizeStore';
|
||||
$store_customisation_task_index = array_search( $task_to_remove, $tasks, true );
|
||||
|
||||
if ( false !== $store_customisation_task_index ) {
|
||||
unset( $tasks[ $store_customisation_task_index ] );
|
||||
}
|
||||
|
||||
self::add_list(
|
||||
array(
|
||||
'id' => 'setup',
|
||||
'title' => __( 'Get ready to start selling', 'woocommerce' ),
|
||||
'tasks' => array(
|
||||
'StoreDetails',
|
||||
'Purchase',
|
||||
'Products',
|
||||
'WooCommercePayments',
|
||||
'Payments',
|
||||
'Tax',
|
||||
'Shipping',
|
||||
'Marketing',
|
||||
'Appearance',
|
||||
),
|
||||
'tasks' => $tasks,
|
||||
'display_progress_header' => true,
|
||||
'event_prefix' => 'tasklist_',
|
||||
'options' => array(
|
||||
@@ -152,45 +173,6 @@ class TaskLists {
|
||||
),
|
||||
)
|
||||
);
|
||||
self::add_list(
|
||||
array(
|
||||
'id' => 'setup_two_column',
|
||||
'hidden_id' => 'setup',
|
||||
'title' => __( 'Get ready to start selling', 'woocommerce' ),
|
||||
'tasks' => array(
|
||||
'Products',
|
||||
'WooCommercePayments',
|
||||
'Payments',
|
||||
'Tax',
|
||||
'Shipping',
|
||||
'Marketing',
|
||||
'Appearance',
|
||||
),
|
||||
'event_prefix' => 'tasklist_',
|
||||
)
|
||||
);
|
||||
self::add_list(
|
||||
array(
|
||||
'id' => 'extended_two_column',
|
||||
'hidden_id' => 'extended',
|
||||
'title' => __( 'Things to do next', 'woocommerce' ),
|
||||
'sort_by' => array(
|
||||
array(
|
||||
'key' => 'is_complete',
|
||||
'order' => 'asc',
|
||||
),
|
||||
array(
|
||||
'key' => 'level',
|
||||
'order' => 'asc',
|
||||
),
|
||||
),
|
||||
'tasks' => array(
|
||||
'AdditionalPayments',
|
||||
'GetMobileApp',
|
||||
),
|
||||
'event_prefix' => 'extended_tasklist_',
|
||||
)
|
||||
);
|
||||
|
||||
if ( Features::is_enabled( 'shipping-smart-defaults' ) ) {
|
||||
self::add_task(
|
||||
@@ -200,13 +182,6 @@ class TaskLists {
|
||||
)
|
||||
);
|
||||
|
||||
self::add_task(
|
||||
'extended_two_column',
|
||||
new ReviewShippingOptions(
|
||||
self::get_list( 'extended_two_column' )
|
||||
)
|
||||
);
|
||||
|
||||
// Tasklist that will never be shown in homescreen,
|
||||
// used for having tasks that are accessed by other means.
|
||||
self::add_list(
|
||||
@@ -225,7 +200,6 @@ class TaskLists {
|
||||
if ( ! wp_is_mobile() ) { // Permit In-App Marketplace Tour on desktops only.
|
||||
$tour_task = new TourInAppMarketplace();
|
||||
self::add_task( 'extended', $tour_task );
|
||||
self::add_task( 'extended_two_column', $tour_task );
|
||||
}
|
||||
|
||||
if ( has_filter( 'woocommerce_admin_experimental_onboarding_tasklists' ) ) {
|
||||
@@ -253,7 +227,7 @@ class TaskLists {
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporarily store the active task to persist across page loads when neccessary.
|
||||
* Temporarily store the active task to persist across page loads when necessary.
|
||||
* Most tasks do not need this.
|
||||
*/
|
||||
public static function set_active_task() {
|
||||
@@ -472,7 +446,7 @@ class TaskLists {
|
||||
|
||||
foreach ( $submenu['woocommerce'] as $key => $menu_item ) {
|
||||
if ( 0 === strpos( $menu_item[0], _x( 'Home', 'Admin menu name', 'woocommerce' ) ) ) {
|
||||
$submenu['woocommerce'][ $key ][0] .= ' <span class="awaiting-mod update-plugins remaining-tasks-badge count-' . esc_attr( $tasks_count ) . '">' . number_format_i18n( $tasks_count ) . '</span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$submenu['woocommerce'][ $key ][0] .= ' <span class="awaiting-mod update-plugins remaining-tasks-badge woocommerce-task-list-remaining-tasks-badge"><span class="count-' . esc_attr( $tasks_count ) . '">' . absint( $tasks_count ) . '</span></span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
|
||||
use Automattic\WooCommerce\Admin\Features\Features;
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\Payments;
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks\WooCommercePayments;
|
||||
use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\Init;
|
||||
|
||||
/**
|
||||
* Payments Task
|
||||
@@ -14,10 +15,18 @@ class AdditionalPayments extends Payments {
|
||||
|
||||
/**
|
||||
* Used to cache is_complete() method result.
|
||||
*
|
||||
* @var null
|
||||
*/
|
||||
private $is_complete_result = null;
|
||||
|
||||
/**
|
||||
* Used to cache can_view() method result.
|
||||
*
|
||||
* @var null
|
||||
*/
|
||||
private $can_view_result = null;
|
||||
|
||||
|
||||
/**
|
||||
* ID.
|
||||
@@ -67,8 +76,8 @@ class AdditionalPayments extends Payments {
|
||||
* @return bool
|
||||
*/
|
||||
public function is_complete() {
|
||||
if ( $this->is_complete_result === null ) {
|
||||
$this->is_complete_result = self::has_gateways();
|
||||
if ( null === $this->is_complete_result ) {
|
||||
$this->is_complete_result = self::has_enabled_additional_gateways();
|
||||
}
|
||||
|
||||
return $this->is_complete_result;
|
||||
@@ -85,33 +94,102 @@ class AdditionalPayments extends Payments {
|
||||
return false;
|
||||
}
|
||||
|
||||
$woocommerce_payments = new WooCommercePayments();
|
||||
|
||||
if ( ! $woocommerce_payments->is_requested() || ! $woocommerce_payments->is_supported() || ! $woocommerce_payments->is_connected() ) {
|
||||
// Hide task if WC Pay is not installed via OBW, or is not connected, or the store is located in a country that is not supported by WC Pay.
|
||||
return false;
|
||||
if ( null !== $this->can_view_result ) {
|
||||
return $this->can_view_result;
|
||||
}
|
||||
if ( $this->get_parent_id() === 'extended_two_column' && WooCommercePayments::is_connected() ) {
|
||||
|
||||
// Show task if woocommerce-payments is connected or if there are any suggested gateways in other category enabled.
|
||||
$this->can_view_result = (
|
||||
WooCommercePayments::is_connected() ||
|
||||
self::has_enabled_other_category_gateways()
|
||||
);
|
||||
|
||||
// Early return if task is not visible.
|
||||
if ( ! $this->can_view_result ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
// Show task if there are any suggested gateways in additional category.
|
||||
$this->can_view_result = ! empty( self::get_suggestion_gateways( 'category_additional' ) );
|
||||
|
||||
return $this->can_view_result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the store has any enabled gateways.
|
||||
* Check if the store has any enabled gateways in other category.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_gateways() {
|
||||
private static function has_enabled_other_category_gateways() {
|
||||
$other_gateways = self::get_suggestion_gateways( 'category_other' );
|
||||
$other_gateways_ids = wp_list_pluck( $other_gateways, 'id' );
|
||||
|
||||
return self::has_enabled_gateways(
|
||||
function( $gateway ) use ( $other_gateways_ids ) {
|
||||
return in_array( $gateway->id, $other_gateways_ids, true );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the store has any enabled gateways in additional category.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function has_enabled_additional_gateways() {
|
||||
$additional_gateways = self::get_suggestion_gateways( 'category_additional' );
|
||||
$additional_gateways_ids = wp_list_pluck( $additional_gateways, 'id' );
|
||||
|
||||
return self::has_enabled_gateways(
|
||||
function( $gateway ) use ( $additional_gateways_ids ) {
|
||||
return 'yes' === $gateway->enabled
|
||||
&& in_array( $gateway->id, $additional_gateways_ids, true );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the store has any enabled gateways based on the given criteria.
|
||||
*
|
||||
* @param callable|null $filter A callback function to filter the gateways.
|
||||
* @return bool
|
||||
*/
|
||||
private static function has_enabled_gateways( $filter = null ) {
|
||||
$gateways = WC()->payment_gateways->get_available_payment_gateways();
|
||||
$enabled_gateways = array_filter(
|
||||
$gateways,
|
||||
function( $gateway ) {
|
||||
return 'yes' === $gateway->enabled && 'woocommerce_payments' !== $gateway->id;
|
||||
function( $gateway ) use ( $filter ) {
|
||||
if ( is_callable( $filter ) ) {
|
||||
return 'yes' === $gateway->enabled && call_user_func( $filter, $gateway );
|
||||
} else {
|
||||
return 'yes' === $gateway->enabled;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return ! empty( $enabled_gateways );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of gateways to suggest.
|
||||
*
|
||||
* @param string $filter_by Filter by category. "category_additional" or "category_other".
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private static function get_suggestion_gateways( $filter_by = 'category_additional' ) {
|
||||
$country = wc_get_base_location()['country'];
|
||||
$plugin_suggestions = Init::get_suggestions();
|
||||
$plugin_suggestions = array_filter(
|
||||
$plugin_suggestions,
|
||||
function( $plugin ) use ( $country, $filter_by ) {
|
||||
if ( ! isset( $plugin->{$filter_by} ) || ! isset( $plugin->plugins[0] ) ) {
|
||||
return false;
|
||||
}
|
||||
return in_array( $country, $plugin->{$filter_by}, true );
|
||||
}
|
||||
);
|
||||
return $plugin_suggestions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,10 +76,11 @@ class Appearance extends Task {
|
||||
*/
|
||||
public function get_additional_data() {
|
||||
return array(
|
||||
'has_homepage' => self::has_homepage(),
|
||||
'has_products' => Products::has_products(),
|
||||
'stylesheet' => get_option( 'stylesheet' ),
|
||||
'theme_mods' => get_theme_mods(),
|
||||
'has_homepage' => self::has_homepage(),
|
||||
'has_products' => Products::has_products(),
|
||||
'stylesheet' => get_option( 'stylesheet' ),
|
||||
'theme_mods' => get_theme_mods(),
|
||||
'support_custom_logo' => false !== get_theme_support( 'custom-logo' ),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\Features\OnboardingTasks\Tasks;
|
||||
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
|
||||
|
||||
/**
|
||||
* Customize Your Store Task
|
||||
*/
|
||||
class CustomizeStore extends Task {
|
||||
/**
|
||||
* ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_id() {
|
||||
return 'customize-store';
|
||||
}
|
||||
|
||||
/**
|
||||
* Title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
return __( 'Customize your store ', '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 get_option( 'woocommerce_admin_customize_store_completed' ) === 'yes';
|
||||
}
|
||||
|
||||
/**
|
||||
* Task visibility.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_view() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_action_url() {
|
||||
return admin_url( 'wp-admin/admin.php?page=wc-admin&path=%2Fcustomize-store' );
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,16 @@ class StoreDetails extends Task {
|
||||
* @return bool
|
||||
*/
|
||||
public function is_complete() {
|
||||
$country = WC()->countries->get_base_country();
|
||||
$country_locale = WC()->countries->get_country_locale();
|
||||
$locale = $country_locale[ $country ] ?? array();
|
||||
|
||||
$hide_postcode = $locale['postcode']['hidden'] ?? false;
|
||||
// If postcode is hidden, just check that the store address and city are set.
|
||||
if ( $hide_postcode ) {
|
||||
return get_option( 'woocommerce_store_address', '' ) !== '' && get_option( 'woocommerce_store_city', '' ) !== '';
|
||||
}
|
||||
|
||||
// Mark as completed if the store address, city and postcode are set. We don't need to check the country because it's set by default.
|
||||
return get_option( 'woocommerce_store_address', '' ) !== '' && get_option( 'woocommerce_store_city', '' ) !== '' &&
|
||||
get_option( 'woocommerce_store_postcode', '' ) !== '';
|
||||
|
||||
@@ -6,12 +6,19 @@ use Automattic\WooCommerce\Internal\Admin\Onboarding\OnboardingProfile;
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
|
||||
use Automattic\WooCommerce\Admin\PluginsHelper;
|
||||
use Automattic\WooCommerce\Admin\Features\PaymentGatewaySuggestions\Init as Suggestions;
|
||||
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskList;
|
||||
use Automattic\WooCommerce\Internal\Admin\WCPayPromotion\Init as WCPayPromotionInit;
|
||||
|
||||
/**
|
||||
* WooCommercePayments Task
|
||||
*/
|
||||
class WooCommercePayments extends Task {
|
||||
/**
|
||||
* Used to cache is_complete() method result.
|
||||
*
|
||||
* @var null
|
||||
*/
|
||||
private $is_complete_result = null;
|
||||
|
||||
/**
|
||||
* ID.
|
||||
*
|
||||
@@ -27,7 +34,7 @@ class WooCommercePayments extends Task {
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
return __( 'Set up WooCommerce Payments', 'woocommerce' );
|
||||
return __( 'Set up WooPayments', 'woocommerce' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +44,7 @@ class WooCommercePayments extends Task {
|
||||
*/
|
||||
public function get_content() {
|
||||
return __(
|
||||
"You're only one step away from getting paid. Verify your business details to start managing transactions with WooCommerce Payments.",
|
||||
"You're only one step away from getting paid. Verify your business details to start managing transactions with WooPayments.",
|
||||
'woocommerce'
|
||||
);
|
||||
}
|
||||
@@ -66,8 +73,15 @@ class WooCommercePayments extends Task {
|
||||
* @return string
|
||||
*/
|
||||
public function get_additional_info() {
|
||||
if ( WCPayPromotionInit::is_woopay_eligible() ) {
|
||||
return __(
|
||||
'By using WooPayments you agree to be bound by our <a href="https://wordpress.com/tos/" target="_blank">Terms of Service</a> (including WooPay <a href="https://wordpress.com/tos/#more-woopay-specifically" target="_blank">merchant terms</a>) and acknowledge that you have read our <a href="https://automattic.com/privacy/" target="_blank">Privacy Policy</a>',
|
||||
'woocommerce'
|
||||
);
|
||||
}
|
||||
|
||||
return __(
|
||||
'By using WooCommerce Payments you agree to be bound by our <a href="https://wordpress.com/tos/" target="_blank">Terms of Service</a> and acknowledge that you have read our <a href="https://automattic.com/privacy/" target="_blank">Privacy Policy</a>',
|
||||
'By using WooPayments you agree to be bound by our <a href="https://wordpress.com/tos/" target="_blank">Terms of Service</a> and acknowledge that you have read our <a href="https://automattic.com/privacy/" target="_blank">Privacy Policy</a>',
|
||||
'woocommerce'
|
||||
);
|
||||
}
|
||||
@@ -78,7 +92,11 @@ class WooCommercePayments extends Task {
|
||||
* @return bool
|
||||
*/
|
||||
public function is_complete() {
|
||||
return self::is_connected();
|
||||
if ( null === $this->is_complete_result ) {
|
||||
$this->is_complete_result = self::is_connected();
|
||||
}
|
||||
|
||||
return $this->is_complete_result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,8 +109,7 @@ class WooCommercePayments extends Task {
|
||||
|
||||
return ! $payments->is_complete() && // Do not re-display the task if the "add payments" task has already been completed.
|
||||
self::is_installed() &&
|
||||
self::is_supported() &&
|
||||
( $this->get_parent_id() !== 'setup_two_column' || ! self::is_connected() );
|
||||
self::is_supported();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -317,8 +317,8 @@ class DefaultPaymentGateways {
|
||||
),
|
||||
array(
|
||||
'id' => 'payfast',
|
||||
'title' => __( 'PayFast', 'woocommerce' ),
|
||||
'content' => __( 'The PayFast extension for WooCommerce enables you to accept payments by Credit Card and EFT via one of South Africa’s most popular payment gateways. No setup fees or monthly subscription costs. Selecting this extension will configure your store to use South African rands as the selected currency.', 'woocommerce' ),
|
||||
'title' => __( 'Payfast', 'woocommerce' ),
|
||||
'content' => __( 'The Payfast extension for WooCommerce enables you to accept payments by Credit Card and EFT via one of South Africa’s most popular payment gateways. No setup fees or monthly subscription costs. Selecting this extension will configure your store to use South African rands as the selected currency.', 'woocommerce' ),
|
||||
'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/payfast.png',
|
||||
'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/payfast.png',
|
||||
'plugins' => array( 'woocommerce-payfast-gateway' ),
|
||||
@@ -390,10 +390,58 @@ class DefaultPaymentGateways {
|
||||
'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/payment_methods/72x72/paypal.png',
|
||||
'plugins' => array( 'woocommerce-paypal-payments' ),
|
||||
'is_visible' => array(
|
||||
(object) array(
|
||||
'type' => 'base_location_country',
|
||||
'value' => 'IN',
|
||||
'operation' => '!=',
|
||||
self::get_rules_for_countries(
|
||||
array(
|
||||
'US',
|
||||
'CA',
|
||||
'MX',
|
||||
'BR',
|
||||
'AR',
|
||||
'CL',
|
||||
'CO',
|
||||
'EC',
|
||||
'PE',
|
||||
'UY',
|
||||
'VE',
|
||||
'AT',
|
||||
'BE',
|
||||
'BG',
|
||||
'HR',
|
||||
'CH',
|
||||
'CY',
|
||||
'CZ',
|
||||
'DK',
|
||||
'EE',
|
||||
'ES',
|
||||
'FI',
|
||||
'FR',
|
||||
'DE',
|
||||
'GB',
|
||||
'GR',
|
||||
'HU',
|
||||
'IE',
|
||||
'IT',
|
||||
'LV',
|
||||
'LT',
|
||||
'LU',
|
||||
'MT',
|
||||
'NL',
|
||||
'NO',
|
||||
'PL',
|
||||
'PT',
|
||||
'RO',
|
||||
'SK',
|
||||
'SL',
|
||||
'SE',
|
||||
'AU',
|
||||
'NZ',
|
||||
'HK',
|
||||
'JP',
|
||||
'SG',
|
||||
'CN',
|
||||
'ID',
|
||||
'IN',
|
||||
)
|
||||
),
|
||||
self::get_rules_for_cbd( false ),
|
||||
),
|
||||
@@ -446,7 +494,6 @@ class DefaultPaymentGateways {
|
||||
'SG',
|
||||
'CN',
|
||||
'ID',
|
||||
'IN',
|
||||
),
|
||||
'category_additional' => array(
|
||||
'US',
|
||||
@@ -500,6 +547,7 @@ class DefaultPaymentGateways {
|
||||
'SG',
|
||||
'CN',
|
||||
'ID',
|
||||
'IN',
|
||||
),
|
||||
),
|
||||
array(
|
||||
@@ -548,7 +596,13 @@ class DefaultPaymentGateways {
|
||||
'JP',
|
||||
)
|
||||
),
|
||||
self::get_rules_for_selling_venues( array( 'brick-mortar', 'brick-mortar-other' ) ),
|
||||
(object) array(
|
||||
'type' => 'or',
|
||||
'operands' => (object) array(
|
||||
self::get_rules_for_selling_venues( array( 'brick-mortar', 'brick-mortar-other' ) ),
|
||||
self::get_rules_selling_offline(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -677,6 +731,7 @@ class DefaultPaymentGateways {
|
||||
'AR',
|
||||
'CL',
|
||||
'CO',
|
||||
'EC',
|
||||
'PE',
|
||||
'UY',
|
||||
'MX',
|
||||
@@ -689,6 +744,7 @@ class DefaultPaymentGateways {
|
||||
'AR',
|
||||
'CL',
|
||||
'CO',
|
||||
'EC',
|
||||
'PE',
|
||||
'UY',
|
||||
'MX',
|
||||
@@ -699,15 +755,15 @@ class DefaultPaymentGateways {
|
||||
// This is for backwards compatibility only (WC < 5.10.0-dev or WCA < 2.9.0-dev).
|
||||
array(
|
||||
'id' => 'woocommerce_payments',
|
||||
'title' => __( 'WooCommerce Payments', 'woocommerce' ),
|
||||
'title' => __( 'WooPayments', 'woocommerce' ),
|
||||
'content' => __(
|
||||
'Manage transactions without leaving your WordPress Dashboard. Only with WooCommerce Payments.',
|
||||
'Manage transactions without leaving your WordPress Dashboard. Only with WooPayments.',
|
||||
'woocommerce'
|
||||
),
|
||||
'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/wcpay.svg',
|
||||
'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/wcpay.svg',
|
||||
'plugins' => array( 'woocommerce-payments' ),
|
||||
'description' => __( 'With WooCommerce Payments, you can securely accept major cards, Apple Pay, and payments in over 100 currencies. Track cash flow and manage recurring revenue directly from your store’s dashboard - with no setup costs or monthly fees.', 'woocommerce' ),
|
||||
'description' => __( 'With WooPayments, you can securely accept major cards, Apple Pay, and payments in over 100 currencies. Track cash flow and manage recurring revenue directly from your store’s dashboard - with no setup costs or monthly fees.', 'woocommerce' ),
|
||||
'is_visible' => array(
|
||||
self::get_rules_for_cbd( false ),
|
||||
self::get_rules_for_countries( self::get_wcpay_countries() ),
|
||||
@@ -741,15 +797,15 @@ class DefaultPaymentGateways {
|
||||
),
|
||||
array(
|
||||
'id' => 'woocommerce_payments:without-in-person-payments',
|
||||
'title' => __( 'WooCommerce Payments', 'woocommerce' ),
|
||||
'title' => __( 'WooPayments', 'woocommerce' ),
|
||||
'content' => __(
|
||||
'Manage transactions without leaving your WordPress Dashboard. Only with WooCommerce Payments.',
|
||||
'Manage transactions without leaving your WordPress Dashboard. Only with WooPayments.',
|
||||
'woocommerce'
|
||||
),
|
||||
'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/wcpay.svg',
|
||||
'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/wcpay.svg',
|
||||
'plugins' => array( 'woocommerce-payments' ),
|
||||
'description' => __( 'With WooCommerce Payments, you can securely accept major cards, Apple Pay, and payments in over 100 currencies. Track cash flow and manage recurring revenue directly from your store’s dashboard - with no setup costs or monthly fees.', 'woocommerce' ),
|
||||
'description' => __( 'With WooPayments, you can securely accept major cards, Apple Pay, and payments in over 100 currencies. Track cash flow and manage recurring revenue directly from your store’s dashboard - with no setup costs or monthly fees.', 'woocommerce' ),
|
||||
'is_visible' => array(
|
||||
self::get_rules_for_cbd( false ),
|
||||
self::get_rules_for_countries( array_diff( self::get_wcpay_countries(), array( 'US', 'CA' ) ) ),
|
||||
@@ -776,15 +832,15 @@ class DefaultPaymentGateways {
|
||||
// This is the same as the above, but with a different description for countries that support in-person payments such as US and CA.
|
||||
array(
|
||||
'id' => 'woocommerce_payments:with-in-person-payments',
|
||||
'title' => __( 'WooCommerce Payments', 'woocommerce' ),
|
||||
'title' => __( 'WooPayments', 'woocommerce' ),
|
||||
'content' => __(
|
||||
'Manage transactions without leaving your WordPress Dashboard. Only with WooCommerce Payments.',
|
||||
'Manage transactions without leaving your WordPress Dashboard. Only with WooPayments.',
|
||||
'woocommerce'
|
||||
),
|
||||
'image' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/wcpay.svg',
|
||||
'image_72x72' => WC_ADMIN_IMAGES_FOLDER_URL . '/onboarding/wcpay.svg',
|
||||
'plugins' => array( 'woocommerce-payments' ),
|
||||
'description' => __( 'With WooCommerce Payments, you can securely accept major cards, Apple Pay, and payments in over 100 currencies – with no setup costs or monthly fees – and you can now accept in-person payments with the Woo mobile app.', 'woocommerce' ),
|
||||
'description' => __( 'With WooPayments, you can securely accept major cards, Apple Pay, and payments in over 100 currencies – with no setup costs or monthly fees – and you can now accept in-person payments with the Woo mobile app.', 'woocommerce' ),
|
||||
'is_visible' => array(
|
||||
self::get_rules_for_cbd( false ),
|
||||
self::get_rules_for_countries( array( 'US', 'CA' ) ),
|
||||
@@ -848,7 +904,7 @@ class DefaultPaymentGateways {
|
||||
* @return array Array of countries.
|
||||
*/
|
||||
public static function get_wcpay_countries() {
|
||||
return array( 'US', 'PR', 'AU', 'CA', 'CY', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'IE', 'IT', 'LU', 'LT', 'LV', 'NO', 'NZ', 'MT', 'AT', 'BE', 'NL', 'PL', 'PT', 'CH', 'HK', 'SI', 'SK', 'SG' );
|
||||
return array( 'US', 'PR', 'AU', 'CA', 'CY', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'IE', 'IT', 'LU', 'LT', 'LV', 'NO', 'NZ', 'MT', 'AT', 'BE', 'NL', 'PL', 'PT', 'CH', 'HK', 'SI', 'SK', 'SG', 'BG', 'CZ', 'HR', 'HU', 'RO', 'SE', 'JP', 'AE' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -907,6 +963,29 @@ class DefaultPaymentGateways {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rules for when selling offline for core profiler.
|
||||
*
|
||||
* @return object Rules to match.
|
||||
*/
|
||||
public static function get_rules_selling_offline() {
|
||||
return (object) array(
|
||||
'type' => 'option',
|
||||
'transformers' => array(
|
||||
(object) array(
|
||||
'use' => 'dot_notation',
|
||||
'arguments' => (object) array(
|
||||
'path' => 'selling_online_answer',
|
||||
),
|
||||
),
|
||||
),
|
||||
'option_name' => 'woocommerce_onboarding_profile',
|
||||
'operation' => 'contains',
|
||||
'value' => 'no_im_selling_offline',
|
||||
'default' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default rules for CBD based on given argument.
|
||||
*
|
||||
@@ -1107,7 +1186,7 @@ class DefaultPaymentGateways {
|
||||
'BO' => [],
|
||||
'CL' => [ 'woo-mercado-pago-custom', 'ppcp-gateway' ],
|
||||
'CO' => [ 'woo-mercado-pago-custom', 'ppcp-gateway' ],
|
||||
'EC' => [ 'ppcp-gateway' ],
|
||||
'EC' => [ 'woo-mercado-pago-custom', 'ppcp-gateway' ],
|
||||
'FK' => [],
|
||||
'GF' => [],
|
||||
'GY' => [],
|
||||
@@ -1153,9 +1232,9 @@ class DefaultPaymentGateways {
|
||||
'GU' => [],
|
||||
'ID' => [ 'stripe', 'ppcp-gateway' ],
|
||||
'IN' => [ 'stripe', 'razorpay', 'payubiz', 'ppcp-gateway' ],
|
||||
'ZA' => [ 'payfast', 'paystack', 'ppcp-gateway' ],
|
||||
'NG' => [ 'paystack', 'ppcp-gateway' ],
|
||||
'GH' => [ 'paystack', 'ppcp-gateway' ],
|
||||
'ZA' => [ 'payfast', 'paystack' ],
|
||||
'NG' => [ 'paystack' ],
|
||||
'GH' => [ 'paystack' ],
|
||||
);
|
||||
|
||||
// If the country code is not in the list, return default priority.
|
||||
|
||||
@@ -20,10 +20,32 @@ class BlockRegistry {
|
||||
* Array of all available product blocks.
|
||||
*/
|
||||
const PRODUCT_BLOCKS = [
|
||||
'woocommerce/product-name',
|
||||
'woocommerce/product-pricing',
|
||||
'woocommerce/conditional',
|
||||
'woocommerce/product-catalog-visibility-field',
|
||||
'woocommerce/product-category-field',
|
||||
'woocommerce/product-checkbox-field',
|
||||
'woocommerce/product-collapsible',
|
||||
'woocommerce/product-description-field',
|
||||
'woocommerce/product-images-field',
|
||||
'woocommerce/product-inventory-email-field',
|
||||
'woocommerce/product-sku-field',
|
||||
'woocommerce/product-name-field',
|
||||
'woocommerce/product-pricing-field',
|
||||
'woocommerce/product-radio-field',
|
||||
'woocommerce/product-regular-price-field',
|
||||
'woocommerce/product-sale-price-field',
|
||||
'woocommerce/product-schedule-sale-fields',
|
||||
'woocommerce/product-section',
|
||||
'woocommerce/product-shipping-class-field',
|
||||
'woocommerce/product-shipping-dimensions-fields',
|
||||
'woocommerce/product-summary-field',
|
||||
'woocommerce/product-tab',
|
||||
'woocommerce/product-inventory-quantity-field',
|
||||
'woocommerce/product-toggle-field',
|
||||
'woocommerce/product-variation-items-field',
|
||||
'woocommerce/product-variations-fields',
|
||||
'woocommerce/product-password-field',
|
||||
'woocommerce/product-has-variations-notice',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,32 +15,52 @@ use WP_Block_Editor_Context;
|
||||
* Loads assets related to the product block editor.
|
||||
*/
|
||||
class Init {
|
||||
|
||||
const FEATURE_ID = 'product-block-editor';
|
||||
|
||||
/**
|
||||
* Option name used to toggle this feature.
|
||||
*/
|
||||
const TOGGLE_OPTION_NAME = 'woocommerce_' . self::FEATURE_ID . '_enabled';
|
||||
|
||||
/**
|
||||
* The context name used to identify the editor.
|
||||
*/
|
||||
const EDITOR_CONTEXT_NAME = 'woocommerce/edit-product';
|
||||
|
||||
/**
|
||||
* Supported post types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $supported_post_types = array( 'simple' );
|
||||
|
||||
/**
|
||||
* Redirection controller.
|
||||
*
|
||||
* @var RedirectionController
|
||||
*/
|
||||
private $redirection_controller;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( ! Features::is_enabled( 'new-product-management-experience' ) && Features::is_enabled( self::FEATURE_ID ) ) {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
|
||||
add_action( 'get_edit_post_link', array( $this, 'update_edit_product_link' ), 10, 2 );
|
||||
if ( Features::is_enabled( 'product-variation-management' ) ) {
|
||||
array_push($this->supported_post_types, 'variable');
|
||||
}
|
||||
if ( Features::is_enabled( self::FEATURE_ID ) ) {
|
||||
|
||||
$this->redirection_controller = new RedirectionController( $this->supported_post_types );
|
||||
|
||||
if ( \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'product_block_editor' ) ) {
|
||||
if ( ! Features::is_enabled( 'new-product-management-experience' ) ) {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'dequeue_conflicting_styles' ), 100 );
|
||||
add_action( 'get_edit_post_link', array( $this, 'update_edit_product_link' ), 10, 2 );
|
||||
}
|
||||
add_filter( 'woocommerce_admin_get_user_data_fields', array( $this, 'add_user_data_fields' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
add_filter( 'woocommerce_register_post_type_product', array( $this, 'add_product_template' ) );
|
||||
|
||||
add_action( 'current_screen', array( $this, 'set_current_screen_to_block_editor_if_wc_admin' ) );
|
||||
|
||||
$block_registry = new BlockRegistry();
|
||||
$block_registry->init();
|
||||
|
||||
$tracks = new Tracks();
|
||||
$tracks->init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +76,9 @@ class Init {
|
||||
|
||||
$editor_settings = array();
|
||||
if ( ! empty( $post_type_object->template ) ) {
|
||||
$editor_settings['template'] = $post_type_object->template;
|
||||
$editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false;
|
||||
$editor_settings['template'] = $post_type_object->template;
|
||||
$editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false;
|
||||
$editor_settings['__unstableResolvedAssets'] = $this->get_resolved_assets();
|
||||
}
|
||||
|
||||
$editor_settings = get_block_editor_settings( $editor_settings, $block_editor_context );
|
||||
@@ -75,6 +96,7 @@ class Init {
|
||||
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( $editor_settings['blockCategories'] ) ),
|
||||
'before'
|
||||
);
|
||||
wp_tinymce_inline_scripts();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,6 +117,17 @@ class Init {
|
||||
do_action( 'enqueue_block_editor_assets' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dequeue conflicting styles.
|
||||
*/
|
||||
public function dequeue_conflicting_styles() {
|
||||
if ( ! PageController::is_admin_or_embed_page() ) {
|
||||
return;
|
||||
}
|
||||
// Dequeing this to avoid conflicts, until we remove the 'woocommerce-page' class.
|
||||
wp_dequeue_style( 'woocommerce-blocktheme' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the edit product links when the new experience is enabled.
|
||||
*
|
||||
@@ -116,6 +149,105 @@ class Init {
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resolved assets needed for the iframe editor.
|
||||
*
|
||||
* @return array Styles and scripts.
|
||||
*/
|
||||
private function get_resolved_assets() {
|
||||
if ( function_exists( 'gutenberg_resolve_assets_override' ) ) {
|
||||
return gutenberg_resolve_assets_override();
|
||||
}
|
||||
|
||||
global $pagenow;
|
||||
|
||||
$script_handles = array(
|
||||
'wp-polyfill',
|
||||
);
|
||||
// Note for core merge: only 'wp-edit-blocks' should be in this array.
|
||||
$style_handles = array(
|
||||
'wp-edit-blocks',
|
||||
);
|
||||
|
||||
if ( current_theme_supports( 'wp-block-styles' ) ) {
|
||||
$style_handles[] = 'wp-block-library-theme';
|
||||
}
|
||||
|
||||
if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
|
||||
$style_handles[] = 'wp-widgets';
|
||||
$style_handles[] = 'wp-edit-widgets';
|
||||
}
|
||||
|
||||
$block_registry = \WP_Block_Type_Registry::get_instance();
|
||||
|
||||
foreach ( $block_registry->get_all_registered() as $block_type ) {
|
||||
// In older WordPress versions, like 6.0, these properties are not defined.
|
||||
if ( isset( $block_type->style_handles ) && is_array( $block_type->style_handles ) ) {
|
||||
$style_handles = array_merge( $style_handles, $block_type->style_handles );
|
||||
}
|
||||
|
||||
if ( isset( $block_type->editor_style_handles ) && is_array( $block_type->editor_style_handles ) ) {
|
||||
$style_handles = array_merge( $style_handles, $block_type->editor_style_handles );
|
||||
}
|
||||
|
||||
if ( isset( $block_type->script_handles ) && is_array( $block_type->script_handles ) ) {
|
||||
$script_handles = array_merge( $script_handles, $block_type->script_handles );
|
||||
}
|
||||
}
|
||||
|
||||
$style_handles = array_unique( $style_handles );
|
||||
$done = wp_styles()->done;
|
||||
|
||||
ob_start();
|
||||
|
||||
// We do not need reset styles for the iframed editor.
|
||||
wp_styles()->done = array( 'wp-reset-editor-styles' );
|
||||
wp_styles()->do_items( $style_handles );
|
||||
wp_styles()->done = $done;
|
||||
|
||||
$styles = ob_get_clean();
|
||||
|
||||
$script_handles = array_unique( $script_handles );
|
||||
$done = wp_scripts()->done;
|
||||
|
||||
ob_start();
|
||||
|
||||
wp_scripts()->done = array();
|
||||
wp_scripts()->do_items( $script_handles );
|
||||
wp_scripts()->done = $done;
|
||||
|
||||
$scripts = ob_get_clean();
|
||||
|
||||
/*
|
||||
* Generate font @font-face styles for the site editor iframe.
|
||||
* Use the registered font families for printing.
|
||||
*/
|
||||
if ( class_exists( '\WP_Fonts' ) ) {
|
||||
$wp_fonts = wp_fonts();
|
||||
$registered = $wp_fonts->get_registered_font_families();
|
||||
if ( ! empty( $registered ) ) {
|
||||
$queue = $wp_fonts->queue;
|
||||
$done = $wp_fonts->done;
|
||||
|
||||
$wp_fonts->done = array();
|
||||
$wp_fonts->queue = $registered;
|
||||
|
||||
ob_start();
|
||||
$wp_fonts->do_items();
|
||||
$styles .= ob_get_clean();
|
||||
|
||||
// Reset the Web Fonts API.
|
||||
$wp_fonts->done = $done;
|
||||
$wp_fonts->queue = $queue;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'styles' => $styles,
|
||||
'scripts' => $scripts,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue styles needed for the rich text editor.
|
||||
*
|
||||
@@ -131,6 +263,7 @@ class Init {
|
||||
array(
|
||||
'id' => 'general',
|
||||
'title' => __( 'General', 'woocommerce' ),
|
||||
'order' => 10,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
@@ -138,19 +271,17 @@ class Init {
|
||||
array(
|
||||
'title' => __( 'Basic details', 'woocommerce' ),
|
||||
'description' => __( 'This info will be displayed on the product page, category pages, social media, and search results.', 'woocommerce' ),
|
||||
'icon' => array(
|
||||
'src' => '<svg xmlns="http://www.w3.org/2000/svg" view-box="0 0 24 24"><path fill-rule="evenodd" d="M5 5.5h14a.5.5 0 01.5.5v1.5a.5.5 0 01-.5.5H5a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 9.232A2 2 0 013 7.5V6a2 2 0 012-2h14a2 2 0 012 2v1.5a2 2 0 01-1 1.732V18a2 2 0 01-2 2H6a2 2 0 01-2-2V9.232zm1.5.268V18a.5.5 0 00.5.5h12a.5.5 0 00.5-.5V9.5h-13z" clip-rule="evenodd" /></svg>',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-name',
|
||||
'woocommerce/product-name-field',
|
||||
array(
|
||||
'name' => 'Product name',
|
||||
'name' => 'Product name',
|
||||
'autoFocus' => true,
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-summary',
|
||||
'woocommerce/product-summary-field',
|
||||
),
|
||||
array(
|
||||
'core/columns',
|
||||
@@ -163,11 +294,11 @@ class Init {
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-pricing',
|
||||
'woocommerce/product-regular-price-field',
|
||||
array(
|
||||
'name' => 'regular_price',
|
||||
'name' => 'regular_price',
|
||||
'label' => __( 'List price', 'woocommerce' ),
|
||||
'showPricingSection' => true,
|
||||
'help' => __( 'Manage more settings in <PricingTab>Pricing.</PricingTab>', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -179,9 +310,8 @@ class Init {
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-pricing',
|
||||
'woocommerce/product-sale-price-field',
|
||||
array(
|
||||
'name' => 'sale_price',
|
||||
'label' => __( 'Sale price', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
@@ -191,20 +321,32 @@ class Init {
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
'title' => __( 'Description', 'woocommerce' ),
|
||||
'description' => __( 'What makes this product unique? What are its most important features? Enrich the product page by adding rich content using blocks.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-description-field',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
'title' => __( 'Images', 'woocommerce' ),
|
||||
'description' => sprintf(
|
||||
/* translators: %1$s: Images guide link opening tag. %2$s: Images guide link closing tag.*/
|
||||
__( 'Drag images, upload new ones or select files from your library. For best results, use JPEG files that are 1000 by 1000 pixels or larger. %1$sHow to prepare images?%2$s.', 'woocommerce' ),
|
||||
__( 'Drag images, upload new ones or select files from your library. For best results, use JPEG files that are 1000 by 1000 pixels or larger. %1$sHow to prepare images?%2$s', 'woocommerce' ),
|
||||
'<a href="http://woocommerce.com/#" target="_blank" rel="noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-images',
|
||||
'woocommerce/product-images-field',
|
||||
array(
|
||||
'images' => array(),
|
||||
),
|
||||
@@ -216,10 +358,82 @@ class Init {
|
||||
array(
|
||||
'woocommerce/product-tab',
|
||||
array(
|
||||
'id' => 'pricing',
|
||||
'title' => __( 'Pricing', 'woocommerce' ),
|
||||
'id' => 'organization',
|
||||
'title' => __( 'Organization', 'woocommerce' ),
|
||||
'order' => 15,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
'title' => __( 'Product catalog', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-category-field',
|
||||
array(
|
||||
'name' => 'categories',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-catalog-visibility-field',
|
||||
array(
|
||||
'label' => __( 'Hide in product catalog', 'woocommerce' ),
|
||||
'visibilty' => 'search',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-catalog-visibility-field',
|
||||
array(
|
||||
'label' => __( 'Hide from search results', 'woocommerce' ),
|
||||
'visibilty' => 'catalog',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-checkbox-field',
|
||||
array(
|
||||
'label' => __( 'Enable product reviews', 'woocommerce' ),
|
||||
'property' => 'reviews_allowed',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-password-field',
|
||||
array(
|
||||
'label' => __( 'Require a password', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
'title' => __( 'Attributes', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-attributes-field',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-tab',
|
||||
array(
|
||||
'id' => 'pricing',
|
||||
'title' => __( 'Pricing', 'woocommerce' ),
|
||||
'order' => 20,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-has-variations-notice',
|
||||
array(
|
||||
'id' => 'wc-product-notice-has-options',
|
||||
'content' => __( 'This product has options, such as size or color. You can now manage each variation\'s price and other details individually.', 'woocommerce' ),
|
||||
'buttonText' => __( 'Go to Variations', 'woocommerce' ),
|
||||
'type' => 'info',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
@@ -230,53 +444,55 @@ class Init {
|
||||
'<a href="https://woocommerce.com/posts/how-to-price-products-strategies-expert-tips/" target="_blank" rel="noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
'icon' => array(
|
||||
'src' => '<svg xmlns="http://www.w3.org/2000/svg" view-box="0 0 24 24"><path fill-rule="evenodd" d="M16.83 6.342l.602.3.625-.25.443-.176v12.569l-.443-.178-.625-.25-.603.301-1.444.723-2.41-.804-.475-.158-.474.158-2.41.803-1.445-.722-.603-.3-.625.25-.443.177V6.215l.443.178.625.25.603-.301 1.444-.722 2.41.803.475.158.474-.158 2.41-.803 1.445.722zM20 4l-1.5.6-1 .4-2-1-3 1-3-1-2 1-1-.4L5 4v17l1.5-.6 1-.4 2 1 3-1 3 1 2-1 1 .4 1.5.6V4zm-3.5 6.25v-1.5h-8v1.5h8zm0 3v-1.5h-8v1.5h8zm-8 3v-1.5h8v1.5h-8z" clip-rule="evenodd" /></svg>',
|
||||
),
|
||||
'blockGap' => 'unit-40',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'core/columns',
|
||||
'woocommerce/product-section',
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
'core/column',
|
||||
array(
|
||||
'templateLock' => 'all',
|
||||
),
|
||||
'core/columns',
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-pricing',
|
||||
'core/column',
|
||||
array(
|
||||
'name' => 'regular_price',
|
||||
'label' => __( 'List price', 'woocommerce' ),
|
||||
'showPricingSection' => true,
|
||||
'templateLock' => 'all',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-regular-price-field',
|
||||
array(
|
||||
'name' => 'regular_price',
|
||||
'label' => __( 'List price', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'core/column',
|
||||
array(
|
||||
'templateLock' => 'all',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-sale-price-field',
|
||||
array(
|
||||
'label' => __( 'Sale price', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'core/column',
|
||||
array(
|
||||
'templateLock' => 'all',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-pricing',
|
||||
array(
|
||||
'name' => 'sale_price',
|
||||
'label' => __( 'Sale price', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'woocommerce/product-schedule-sale-fields',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-schedule-sale-fields',
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-radio',
|
||||
'woocommerce/product-radio-field',
|
||||
array(
|
||||
'title' => __( 'Charge sales tax on', 'woocommerce' ),
|
||||
'property' => 'tax_status',
|
||||
@@ -297,7 +513,7 @@ class Init {
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/collapsible',
|
||||
'woocommerce/product-collapsible',
|
||||
array(
|
||||
'toggleText' => __( 'Advanced', 'woocommerce' ),
|
||||
'initialCollapsed' => true,
|
||||
@@ -305,7 +521,7 @@ class Init {
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-radio',
|
||||
'woocommerce/product-radio-field',
|
||||
array(
|
||||
'title' => __( 'Tax class', 'woocommerce' ),
|
||||
'description' => sprintf(
|
||||
@@ -342,8 +558,18 @@ class Init {
|
||||
array(
|
||||
'id' => 'inventory',
|
||||
'title' => __( 'Inventory', 'woocommerce' ),
|
||||
'order' => 30,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-has-variations-notice',
|
||||
array(
|
||||
'id' => 'wc-product-notice-has-options',
|
||||
'content' => __( 'This product has options, such as size or color. You can now manage each variation\'s price and other details individually.', 'woocommerce' ),
|
||||
'buttonText' => __( 'Go to Variations', 'woocommerce' ),
|
||||
'type' => 'info',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
@@ -354,25 +580,24 @@ class Init {
|
||||
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products§ion=inventory' ) . '" target="_blank" rel="noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
'icon' => array(
|
||||
'src' => '<svg width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M2 2H14C14.2761 2 14.5 2.22386 14.5 2.5V9.5H11.5H10C10 10.6046 9.10457 11.5 8 11.5C6.89543 11.5 6 10.6046 6 9.5H4.5H1.5V2.5C1.5 2.22386 1.72386 2 2 2ZM1.5 11V14.5C1.5 14.7761 1.72386 15 2 15H14C14.2761 15 14.5 14.7761 14.5 14.5V11H11.1632C10.6015 12.1825 9.3962 13 8 13C6.6038 13 5.39855 12.1825 4.83682 11H1.5ZM0 9.5V2.5C0 1.39543 0.895431 0.5 2 0.5H14C15.1046 0.5 16 1.39543 16 2.5V9.5V11V14.5C16 15.6046 15.1046 16.5 14 16.5H2C0.895431 16.5 0 15.6046 0 14.5V11V9.5Z" fill="#1E1E1E"/></svg>',
|
||||
),
|
||||
'blockGap' => 'unit-40',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-sku',
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-track-inventory-fields',
|
||||
),
|
||||
array(
|
||||
'woocommerce/collapsible',
|
||||
array(
|
||||
'toggleText' => __( 'Advanced', 'woocommerce' ),
|
||||
'initialCollapsed' => true,
|
||||
'persistRender' => true,
|
||||
),
|
||||
'woocommerce/product-section',
|
||||
array(),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-sku-field',
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-toggle-field',
|
||||
array(
|
||||
'label' => __( 'Track stock quantity for this product', 'woocommerce' ),
|
||||
'property' => 'manage_stock',
|
||||
'disabled' => 'yes' !== get_option( 'woocommerce_manage_stock' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/conditional',
|
||||
array(
|
||||
@@ -382,53 +607,115 @@ class Init {
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-radio',
|
||||
'woocommerce/product-inventory-quantity-field',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/conditional',
|
||||
array(
|
||||
'mustMatch' => array(
|
||||
'manage_stock' => array( false ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-radio-field',
|
||||
array(
|
||||
'title' => __( 'Stock status', 'woocommerce' ),
|
||||
'property' => 'stock_status',
|
||||
'options' => array(
|
||||
array(
|
||||
'title' => __( 'When out of stock', 'woocommerce' ),
|
||||
'property' => 'backorders',
|
||||
'options' => array(
|
||||
'label' => __( 'In stock', 'woocommerce' ),
|
||||
'value' => 'instock',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'Out of stock', 'woocommerce' ),
|
||||
'value' => 'outofstock',
|
||||
),
|
||||
array(
|
||||
'label' => __( 'On backorder', 'woocommerce' ),
|
||||
'value' => 'onbackorder',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-collapsible',
|
||||
array(
|
||||
'toggleText' => __( 'Advanced', 'woocommerce' ),
|
||||
'initialCollapsed' => true,
|
||||
'persistRender' => true,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
'blockGap' => 'unit-40',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/conditional',
|
||||
array(
|
||||
'mustMatch' => array(
|
||||
'manage_stock' => array( true ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-radio-field',
|
||||
array(
|
||||
'label' => __( 'Allow purchases', 'woocommerce' ),
|
||||
'value' => 'yes',
|
||||
),
|
||||
array(
|
||||
'label' => __(
|
||||
'Allow purchases, but notify customers',
|
||||
'woocommerce'
|
||||
'title' => __( 'When out of stock', 'woocommerce' ),
|
||||
'property' => 'backorders',
|
||||
'options' => array(
|
||||
array(
|
||||
'label' => __( 'Allow purchases', 'woocommerce' ),
|
||||
'value' => 'yes',
|
||||
),
|
||||
array(
|
||||
'label' => __(
|
||||
'Allow purchases, but notify customers',
|
||||
'woocommerce'
|
||||
),
|
||||
'value' => 'notify',
|
||||
),
|
||||
array(
|
||||
'label' => __( "Don't allow purchases", 'woocommerce' ),
|
||||
'value' => 'no',
|
||||
),
|
||||
),
|
||||
'value' => 'notify',
|
||||
),
|
||||
array(
|
||||
'label' => __( "Don't allow purchases", 'woocommerce' ),
|
||||
'value' => 'no',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-inventory-email-field',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-inventory-email',
|
||||
'woocommerce/product-checkbox-field',
|
||||
array(
|
||||
'title' => __(
|
||||
'Restrictions',
|
||||
'woocommerce'
|
||||
),
|
||||
'label' => __(
|
||||
'Limit purchases to 1 item per order',
|
||||
'woocommerce'
|
||||
),
|
||||
'property' => 'sold_individually',
|
||||
'tooltip' => __(
|
||||
'When checked, customers will be able to purchase only 1 item in a single order. This is particularly useful for items that have limited quantity, like art or handmade goods.',
|
||||
'woocommerce'
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-checkbox',
|
||||
array(
|
||||
'title' => __(
|
||||
'Restrictions',
|
||||
'woocommerce'
|
||||
),
|
||||
'label' => __(
|
||||
'Limit purchases to 1 item per order',
|
||||
'woocommerce'
|
||||
),
|
||||
'property' => 'sold_individually',
|
||||
'tooltip' => __(
|
||||
'When checked, customers will be able to purchase only 1 item in a single order. This is particularly useful for items that have limited quantity, like art or handmade goods.',
|
||||
'woocommerce'
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -442,8 +729,18 @@ class Init {
|
||||
array(
|
||||
'id' => 'shipping',
|
||||
'title' => __( 'Shipping', 'woocommerce' ),
|
||||
'order' => 40,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-has-variations-notice',
|
||||
array(
|
||||
'id' => 'wc-product-notice-has-options',
|
||||
'content' => __( 'This product has options, such as size or color. You can now manage each variation\'s price and other details individually.', 'woocommerce' ),
|
||||
'buttonText' => __( 'Go to Variations', 'woocommerce' ),
|
||||
'type' => 'info',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
@@ -454,16 +751,10 @@ class Init {
|
||||
'<a href="https://woocommerce.com/posts/how-to-calculate-shipping-costs-for-your-woocommerce-store/" target="_blank" rel="noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
'icon' => array(
|
||||
'src' => '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3.5 7.75C3.5 6.7835 4.2835 6 5.25 6H14.75H15.5V6.75V9H17.25H17.5607L17.7803 9.21967L20.7803 12.2197L21 12.4393V12.75V14.75C21 15.7165 20.2165 16.5 19.25 16.5H19.2377C19.2458 16.5822 19.25 16.6656 19.25 16.75C19.25 18.1307 18.1307 19.25 16.75 19.25C15.3693 19.25 14.25 18.1307 14.25 16.75C14.25 16.6656 14.2542 16.5822 14.2623 16.5H14H10.2377C10.2458 16.5822 10.25 16.6656 10.25 16.75C10.25 18.1307 9.13071 19.25 7.75 19.25C6.36929 19.25 5.25 18.1307 5.25 16.75C5.25 16.6656 5.25418 16.5822 5.26234 16.5H4.25H3.5V15.75V7.75ZM14 15V9.75V9V7.5H5.25C5.11193 7.5 5 7.61193 5 7.75V15H5.96464C6.41837 14.5372 7.05065 14.25 7.75 14.25C8.44935 14.25 9.08163 14.5372 9.53536 15H14ZM18.5354 15H19.25C19.3881 15 19.5 14.8881 19.5 14.75V13.0607L16.9393 10.5H15.5V14.5845C15.8677 14.3717 16.2946 14.25 16.75 14.25C17.4493 14.25 18.0816 14.5372 18.5354 15ZM6.7815 16.5C6.76094 16.5799 6.75 16.6637 6.75 16.75C6.75 17.3023 7.19772 17.75 7.75 17.75C8.30228 17.75 8.75 17.3023 8.75 16.75C8.75 16.6637 8.73906 16.5799 8.7185 16.5C8.60749 16.0687 8.21596 15.75 7.75 15.75C7.28404 15.75 6.89251 16.0687 6.7815 16.5ZM15.7815 16.5C15.7609 16.5799 15.75 16.6637 15.75 16.75C15.75 17.3023 16.1977 17.75 16.75 17.75C17.3023 17.75 17.75 17.3023 17.75 16.75C17.75 16.6637 17.7391 16.5799 17.7185 16.5C17.7144 16.4841 17.7099 16.4683 17.705 16.4526C17.5784 16.0456 17.1987 15.75 16.75 15.75C16.284 15.75 15.8925 16.0687 15.7815 16.5Z" fill="#1E1E1E"/></svg>',
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-shipping-fee-fields',
|
||||
array(
|
||||
'title' => __( 'Shipping fee', 'woocommerce' ),
|
||||
),
|
||||
'woocommerce/product-shipping-class-field',
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-shipping-dimensions-fields',
|
||||
@@ -473,7 +764,86 @@ class Init {
|
||||
),
|
||||
),
|
||||
);
|
||||
if ( Features::is_enabled( 'product-variation-management' ) ) {
|
||||
array_push(
|
||||
$args['template'],
|
||||
array(
|
||||
'woocommerce/product-tab',
|
||||
array(
|
||||
'id' => 'variations',
|
||||
'title' => __( 'Variations', 'woocommerce' ),
|
||||
'order' => 40,
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-variations-fields',
|
||||
array(
|
||||
'description' => sprintf(
|
||||
/* translators: %1$s: Sell your product in multiple variations like size or color. strong opening tag. %2$s: Sell your product in multiple variations like size or color. strong closing tag.*/
|
||||
__( '%1$sSell your product in multiple variations like size or color.%2$s Get started by adding options for the buyers to choose on the product page.', 'woocommerce' ),
|
||||
'<strong>',
|
||||
'</strong>'
|
||||
),
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
'title' => __( 'Variation options', 'woocommerce' ),
|
||||
),
|
||||
array( array( 'woocommerce/product-variations-options-field' ) ),
|
||||
),
|
||||
array(
|
||||
'woocommerce/product-section',
|
||||
array(
|
||||
'title' => __( 'Variations', 'woocommerce' ),
|
||||
),
|
||||
array( array( 'woocommerce/product-variation-items-field' ) ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds fields so that we can store user preferences for the variations block.
|
||||
*
|
||||
* @param array $user_data_fields User data fields.
|
||||
* @return array
|
||||
*/
|
||||
public function add_user_data_fields( $user_data_fields ) {
|
||||
return array_merge(
|
||||
$user_data_fields,
|
||||
array(
|
||||
'variable_product_block_tour_shown',
|
||||
'product_block_variable_options_notice_dismissed',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current screen to the block editor if a wc-admin page.
|
||||
*/
|
||||
public function set_current_screen_to_block_editor_if_wc_admin() {
|
||||
$screen = get_current_screen();
|
||||
|
||||
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
|
||||
// (no idea why I need that phpcs:ignore above, but I'm tired trying to re-write this comment to get it to pass)
|
||||
// we can't check the 'path' query param because client-side routing is used within wc-admin,
|
||||
// so this action handler is only called on the initial page load from the server, which might
|
||||
// not be the product edit page (it mostly likely isn't).
|
||||
if ( PageController::is_admin_page() ) {
|
||||
$screen->is_block_editor( true );
|
||||
|
||||
wp_add_inline_script(
|
||||
'wp-blocks',
|
||||
'wp.blocks && wp.blocks.unstable__bootstrapServerSideBlockDefinitions && wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce Product Editor Redirection Controller
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor;
|
||||
|
||||
use Automattic\WooCommerce\Internal\Admin\WCAdminAssets;
|
||||
|
||||
/**
|
||||
* Handle redirecting to the old or new editor based on features and support.
|
||||
*/
|
||||
class RedirectionController {
|
||||
|
||||
/**
|
||||
* Supported post types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $supported_post_types;
|
||||
|
||||
/**
|
||||
* Set up the hooks used for redirection.
|
||||
*
|
||||
* @param array $supported_post_types Array of supported post types.
|
||||
*/
|
||||
public function __construct( $supported_post_types ) {
|
||||
$this->supported_post_types = $supported_post_types;
|
||||
|
||||
if ( \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'product_block_editor' ) ) {
|
||||
add_action( 'current_screen', array( $this, 'maybe_redirect_to_new_editor' ), 30, 0 );
|
||||
add_action( 'current_screen', array( $this, 'redirect_non_supported_product_types' ), 30, 0 );
|
||||
} else {
|
||||
add_action( 'current_screen', array( $this, 'maybe_redirect_to_old_editor' ), 30, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current screen is the legacy add product screen.
|
||||
*/
|
||||
protected function is_legacy_add_new_screen(): bool {
|
||||
$screen = get_current_screen();
|
||||
return 'post' === $screen->base && 'product' === $screen->post_type && 'add' === $screen->action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current screen is the legacy edit product screen.
|
||||
*/
|
||||
protected function is_legacy_edit_screen(): bool {
|
||||
$screen = get_current_screen();
|
||||
return 'post' === $screen->base
|
||||
&& 'product' === $screen->post_type
|
||||
&& isset( $_GET['post'] )
|
||||
&& isset( $_GET['action'] )
|
||||
&& 'edit' === $_GET['action'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a product is supported by the new experience.
|
||||
*
|
||||
* @param integer $product_id Product ID.
|
||||
*/
|
||||
protected function is_product_supported( $product_id ): bool {
|
||||
$product = $product_id ? wc_get_product( $product_id ) : null;
|
||||
$digital_product = $product->is_downloadable() || $product->is_virtual();
|
||||
return $product && in_array( $product->get_type(), $this->supported_post_types, true ) && ! $digital_product;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects from old product form to the new product form if the
|
||||
* feature `product_block_editor` is enabled.
|
||||
*/
|
||||
public function maybe_redirect_to_new_editor(): void {
|
||||
if ( $this->is_legacy_add_new_screen() ) {
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=wc-admin&path=/add-product' ) );
|
||||
exit();
|
||||
}
|
||||
|
||||
if ( $this->is_legacy_edit_screen() ) {
|
||||
$product_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : null;
|
||||
if ( ! $this->is_product_supported( $product_id ) ) {
|
||||
return;
|
||||
}
|
||||
wp_safe_redirect( admin_url( 'admin.php?page=wc-admin&path=/product/' . $product_id ) );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects from new product form to the old product form if the
|
||||
* feature `product_block_editor` is enabled.
|
||||
*/
|
||||
public function maybe_redirect_to_old_editor(): void {
|
||||
$route = $this->get_parsed_route();
|
||||
|
||||
if ( 'add-product' === $route['page'] ) {
|
||||
wp_safe_redirect( admin_url( 'post-new.php?post_type=product' ) );
|
||||
exit();
|
||||
}
|
||||
|
||||
if ( 'product' === $route['page'] ) {
|
||||
wp_safe_redirect( admin_url( 'post.php?post=' . $route['product_id'] . '&action=edit' ) );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parsed WooCommerce Admin path.
|
||||
*/
|
||||
protected function get_parsed_route(): array {
|
||||
if ( ! \Automattic\WooCommerce\Admin\PageController::is_admin_page() || ! isset( $_GET['path'] ) ) {
|
||||
return array(
|
||||
'page' => null,
|
||||
'product_id' => null,
|
||||
);
|
||||
}
|
||||
|
||||
$path = esc_url_raw( wp_unslash( $_GET['path'] ) );
|
||||
$path_pieces = explode( '/', wp_parse_url( $path, PHP_URL_PATH ) );
|
||||
|
||||
return array(
|
||||
'page' => $path_pieces[1],
|
||||
'product_id' => 'product' === $path_pieces[1] ? absint( $path_pieces[2] ) : null,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect non supported product types to legacy editor.
|
||||
*/
|
||||
public function redirect_non_supported_product_types(): void {
|
||||
$route = $this->get_parsed_route();
|
||||
$product_id = $route['product_id'];
|
||||
|
||||
if ( 'product' === $route['page'] && ! $this->is_product_supported( $product_id ) ) {
|
||||
wp_safe_redirect( admin_url( 'post.php?post=' . $route['product_id'] . '&action=edit' ) );
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* WooCommerce Product Block Editor
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\Features\ProductBlockEditor;
|
||||
|
||||
/**
|
||||
* Add tracks for the product block editor.
|
||||
*/
|
||||
class Tracks {
|
||||
|
||||
/**
|
||||
* Initialize the tracks.
|
||||
*/
|
||||
public function init() {
|
||||
add_filter( 'woocommerce_product_source', array( $this, 'add_product_source' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a URL is a product editor page.
|
||||
*
|
||||
* @param string $url Url to check.
|
||||
* @return boolean
|
||||
*/
|
||||
protected function is_product_editor_page( $url ) {
|
||||
$query_string = wp_parse_url( wp_get_referer(), PHP_URL_QUERY );
|
||||
parse_str( $query_string, $query );
|
||||
|
||||
if ( ! isset( $query['page'] ) || 'wc-admin' !== $query['page'] || ! isset( $query['path'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$path_pieces = explode( '/', $query['path'] );
|
||||
$route = $path_pieces[1];
|
||||
|
||||
return 'add-product' === $route || 'product' === $route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the product source if we're on the product editor page.
|
||||
*
|
||||
* @param string $source Source of product.
|
||||
* @return string
|
||||
*/
|
||||
public function add_product_source( $source ) {
|
||||
if ( $this->is_product_editor_page( wp_get_referer() ) ) {
|
||||
return 'product-block-editor-v1';
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -209,12 +209,29 @@ class DefaultShippingPartners {
|
||||
'available_layouts' => array( 'row', 'column' ),
|
||||
),
|
||||
array(
|
||||
'title' => 'WooCommerce Shipping',
|
||||
'name' => 'WooCommerce Shipping',
|
||||
'slug' => 'woocommerce-services',
|
||||
'description' => __( 'Save time and money by printing your shipping labels right from your computer with WooCommerce Shipping. Try WooCommerce Shipping for free.', 'woocommerce' ),
|
||||
'dependencies' => array( 'jetpack' ),
|
||||
'layout_column' => array(
|
||||
'image' => $asset_base_url . 'wcs-column.svg',
|
||||
'features' => $column_layout_features,
|
||||
'features' => array(
|
||||
array(
|
||||
'icon' => $asset_base_url . 'printer.svg',
|
||||
'title' => __( 'Buy postage when you need it', 'woocommerce' ),
|
||||
'description' => __( 'No need to wonder where that stampbook went.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'icon' => $asset_base_url . 'paper.svg',
|
||||
'title' => __( 'Print at home', 'woocommerce' ),
|
||||
'description' => __( 'Pick up an order, then just pay, print, package and post.', 'woocommerce' ),
|
||||
),
|
||||
array(
|
||||
'icon' => $asset_base_url . 'discount.svg',
|
||||
'title' => __( 'Discounted rates', 'woocommerce' ),
|
||||
'description' => __( 'Access discounted shipping rates with DHL and USPS.', 'woocommerce' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'learn_more_link' => 'https://woocommerce.com/products/shipping/',
|
||||
'is_visible' => array(
|
||||
|
||||
Reference in New Issue
Block a user