rebase code on oct-10-2023
This commit is contained in:
@@ -195,19 +195,6 @@ abstract class WC_Data {
|
||||
* @return bool result
|
||||
*/
|
||||
public function delete( $force_delete = false ) {
|
||||
/**
|
||||
* Filters whether an object deletion should take place. Equivalent to `pre_delete_post`.
|
||||
*
|
||||
* @param mixed $check Whether to go ahead with deletion.
|
||||
* @param WC_Data $this The data object being deleted.
|
||||
* @param bool $force_delete Whether to bypass the trash.
|
||||
*
|
||||
* @since 8.1.0.
|
||||
*/
|
||||
$check = apply_filters( "woocommerce_pre_delete_$this->object_type", null, $this, $force_delete );
|
||||
if ( null !== $check ) {
|
||||
return $check;
|
||||
}
|
||||
if ( $this->data_store ) {
|
||||
$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
|
||||
$this->set_id( 0 );
|
||||
|
||||
@@ -340,7 +340,7 @@ class WC_Admin_Addons {
|
||||
$url
|
||||
);
|
||||
|
||||
echo '<a href="' . esc_url( $url ) . '" class="page-title-action">' . esc_html( $text ) . '</a>' . "\n";
|
||||
echo '<a href="' . esc_url( $url ) . '" class="add-new-h2">' . esc_html( $text ) . '</a>' . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -96,7 +96,7 @@ class WC_Admin_API_Keys {
|
||||
private static function table_list_output() {
|
||||
global $wpdb, $keys_table_list;
|
||||
|
||||
echo '<h2 class="wc-table-list-header">' . esc_html__( 'REST API', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=keys&create-key=1' ) ) . '" class="page-title-action">' . esc_html__( 'Add key', 'woocommerce' ) . '</a></h2>';
|
||||
echo '<h2 class="wc-table-list-header">' . esc_html__( 'REST API', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=keys&create-key=1' ) ) . '" class="add-new-h2">' . esc_html__( 'Add key', 'woocommerce' ) . '</a></h2>';
|
||||
|
||||
// Get the API keys count.
|
||||
$count = $wpdb->get_var( "SELECT COUNT(key_id) FROM {$wpdb->prefix}woocommerce_api_keys WHERE 1 = 1;" );
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
use Automattic\Jetpack\Constants;
|
||||
use Automattic\WooCommerce\Internal\Admin\Orders\Edit as OrderEdit;
|
||||
use Automattic\WooCommerce\Utilities\OrderUtil;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
@@ -216,7 +215,7 @@ class WC_Admin_Meta_Boxes {
|
||||
$post_id = absint( $post_id );
|
||||
|
||||
// $post_id and $post are required
|
||||
if ( empty( $post_id ) || empty( $post ) || ! is_a( $post, 'WP_Post' ) || self::$saved_meta_boxes ) {
|
||||
if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -248,10 +247,6 @@ class WC_Admin_Meta_Boxes {
|
||||
|
||||
// Check the post type.
|
||||
if ( in_array( $post->post_type, wc_get_order_types( 'order-meta-boxes' ), true ) ) {
|
||||
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta for shop order.
|
||||
*
|
||||
|
||||
@@ -295,7 +295,7 @@ class WC_Admin_Webhooks {
|
||||
private static function table_list_output() {
|
||||
global $webhooks_table_list;
|
||||
|
||||
echo '<h2 class="wc-table-list-header">' . esc_html__( 'Webhooks', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=webhooks&edit-webhook=0' ) ) . '" class="page-title-action">' . esc_html__( 'Add webhook', 'woocommerce' ) . '</a></h2>';
|
||||
echo '<h2 class="wc-table-list-header">' . esc_html__( 'Webhooks', 'woocommerce' ) . ' <a href="' . esc_url( admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=webhooks&edit-webhook=0' ) ) . '" class="add-new-h2">' . esc_html__( 'Add webhook', 'woocommerce' ) . '</a></h2>';
|
||||
|
||||
// Get the webhooks count.
|
||||
$data_store = WC_Data_Store::load( 'webhook' );
|
||||
|
||||
@@ -60,8 +60,7 @@
|
||||
$class_html = $current_filter === $key ? 'class="current"' : '';
|
||||
?>
|
||||
<li>
|
||||
<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<a <?php echo $class_html; ?> href="<?php echo esc_url( $url ); ?>">
|
||||
<a <?php echo esc_html( $class_html ); ?> href="<?php echo esc_url( $url ); ?>">
|
||||
<?php echo esc_html( $label ); ?>
|
||||
<span class="count">(<?php echo absint( $counts[ $key ] ); ?>)</span>
|
||||
</a>
|
||||
|
||||
@@ -136,9 +136,10 @@ $current_section_name = __( 'Browse Categories', 'woocommerce' );
|
||||
|
||||
<?php if ( 'Storefront' !== $theme['Name'] && '_featured' !== $current_section ) : ?>
|
||||
<?php
|
||||
$storefront_url = WC_Admin_Addons::add_in_app_purchase_url_params( 'https://woocommerce.com/products/storefront/?utm_source=extensionsscreen&utm_medium=product&utm_campaign=wcaddon' );
|
||||
$storefront_url = WC_Admin_Addons::add_in_app_purchase_url_params( 'https://woocommerce.com/storefront/?utm_source=extensionsscreen&utm_medium=product&utm_campaign=wcaddon' );
|
||||
?>
|
||||
<div class="storefront">
|
||||
<a href="<?php echo esc_url( $storefront_url ); ?>" target="_blank"><img src="<?php echo esc_url( WC()->plugin_url() ); ?>/assets/images/storefront.png" alt="<?php esc_attr_e( 'Storefront', 'woocommerce' ); ?>" /></a>
|
||||
<h2><?php esc_html_e( 'Looking for a WooCommerce theme?', 'woocommerce' ); ?></h2>
|
||||
<p><?php echo wp_kses_post( __( 'We recommend Storefront, the <em>official</em> WooCommerce theme.', 'woocommerce' ) ); ?></p>
|
||||
<p><?php echo wp_kses_post( __( 'Storefront is an intuitive, flexible and <strong>free</strong> WordPress theme offering deep integration with WooCommerce and many of the most popular customer-facing extensions.', 'woocommerce' ) ); ?></p>
|
||||
|
||||
@@ -971,8 +971,6 @@ class WC_AJAX {
|
||||
$data['date_created'] = $data['date_created'] ? $data['date_created']->getTimestamp() : null;
|
||||
$data['date_modified'] = $data['date_modified'] ? $data['date_modified']->getTimestamp() : null;
|
||||
|
||||
unset( $data['meta_data'] );
|
||||
|
||||
$customer_data = apply_filters( 'woocommerce_ajax_get_customer_details', $data, $customer, $user_id );
|
||||
wp_send_json( $customer_data );
|
||||
}
|
||||
@@ -3617,7 +3615,7 @@ class WC_AJAX {
|
||||
* @param array $data Data sent through the heartbeat.
|
||||
* @return array Response to be sent.
|
||||
*/
|
||||
private static function order_refresh_lock( $response, $data ) {
|
||||
private static function order_refresh_lock( $response, $data ) : array {
|
||||
return wc_get_container()->get( Automattic\WooCommerce\Internal\Admin\Orders\EditLock::class )->refresh_lock_ajax( $response, $data );
|
||||
}
|
||||
|
||||
@@ -3630,7 +3628,7 @@ class WC_AJAX {
|
||||
* @param array $data Data sent through the heartbeat.
|
||||
* @return array Response to be sent.
|
||||
*/
|
||||
private static function check_locked_orders( $response, $data ) {
|
||||
private static function check_locked_orders( $response, $data ) : array {
|
||||
return wc_get_container()->get( Automattic\WooCommerce\Internal\Admin\Orders\EditLock::class )->check_locked_orders_ajax( $response, $data );
|
||||
}
|
||||
|
||||
|
||||
@@ -592,7 +592,7 @@ class WC_Countries {
|
||||
'TW' => "{company}\n{last_name} {first_name}\n{address_1}\n{address_2}\n{state}, {city} {postcode}\n{country}",
|
||||
'UG' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}\n{state}, {country}",
|
||||
'US' => "{name}\n{company}\n{address_1}\n{address_2}\n{city}, {state_code} {postcode}\n{country}",
|
||||
'VN' => "{name}\n{company}\n{address_1}\n{address_2}\n{city} {postcode}\n{country}",
|
||||
'VN' => "{name}\n{company}\n{address_1}\n{city}\n{country}",
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,6 @@
|
||||
|
||||
use Automattic\Jetpack\Constants;
|
||||
use Automattic\WooCommerce\Admin\Notes\Notes;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
|
||||
use Automattic\WooCommerce\Internal\Features\FeaturesController;
|
||||
use Automattic\WooCommerce\Internal\ProductAttributesLookup\DataRegenerator;
|
||||
use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register as Download_Directories;
|
||||
use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Synchronize as Download_Directories_Sync;
|
||||
@@ -238,9 +234,6 @@ class WC_Install {
|
||||
'7.7.0' => array(
|
||||
'wc_update_770_remove_multichannel_marketing_feature_options',
|
||||
),
|
||||
'8.1.0' => array(
|
||||
'wc_update_810_migrate_transactional_metadata_for_hpos',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -487,21 +480,9 @@ class WC_Install {
|
||||
self::create_tables();
|
||||
}
|
||||
|
||||
$schema = self::get_schema();
|
||||
|
||||
$feature_controller = wc_get_container()->get( FeaturesController::class );
|
||||
if (
|
||||
$feature_controller->feature_is_enabled( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION )
|
||||
|| $feature_controller->feature_is_enabled( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION )
|
||||
) {
|
||||
$schema .= wc_get_container()
|
||||
->get( OrdersTableDataStore::class )
|
||||
->get_database_schema();
|
||||
}
|
||||
|
||||
$missing_tables = wc_get_container()
|
||||
->get( DatabaseUtil::class )
|
||||
->get_missing_tables( $schema );
|
||||
->get_missing_tables( self::get_schema() );
|
||||
|
||||
if ( 0 < count( $missing_tables ) ) {
|
||||
if ( $modify_notice ) {
|
||||
@@ -1161,15 +1142,15 @@ class WC_Install {
|
||||
$collate = $wpdb->get_charset_collate();
|
||||
}
|
||||
|
||||
$max_index_length = wc_get_container()->get( DatabaseUtil::class )->get_max_index_length();
|
||||
/*
|
||||
* Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
|
||||
* As of WP 4.2, however, they moved to utf8mb4, which uses 4 bytes per character. This means that an index which
|
||||
* used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
|
||||
*/
|
||||
$max_index_length = 191;
|
||||
|
||||
$product_attributes_lookup_table_creation_sql = wc_get_container()->get( DataRegenerator::class )->get_table_creation_sql();
|
||||
|
||||
$feature_controller = wc_get_container()->get( FeaturesController::class );
|
||||
$hpos_enabled =
|
||||
$feature_controller->feature_is_enabled( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION ) || $feature_controller->feature_is_enabled( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION );
|
||||
$hpos_table_schema = $hpos_enabled ? wc_get_container()->get( OrdersTableDataStore::class )->get_database_schema() : '';
|
||||
|
||||
$tables = "
|
||||
CREATE TABLE {$wpdb->prefix}woocommerce_sessions (
|
||||
session_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
@@ -1513,7 +1494,6 @@ CREATE TABLE {$wpdb->prefix}wc_category_lookup (
|
||||
category_id bigint(20) unsigned NOT NULL,
|
||||
PRIMARY KEY (category_tree_id,category_id)
|
||||
) $collate;
|
||||
$hpos_table_schema;
|
||||
";
|
||||
|
||||
return $tables;
|
||||
|
||||
@@ -14,7 +14,6 @@ use Automattic\Jetpack\Constants;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
|
||||
use Automattic\WooCommerce\Utilities\{ FeaturesUtil, OrderUtil, PluginUtil };
|
||||
use Automattic\WooCommerce\Internal\Utilities\BlocksUtil;
|
||||
use Automattic\WooCommerce\Proxies\LegacyProxy;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
@@ -312,7 +311,7 @@ class WC_Tracker {
|
||||
include ABSPATH . '/wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
$plugins = wc_get_container()->get( LegacyProxy::class )->call_function( 'get_plugins' );
|
||||
$plugins = get_plugins();
|
||||
$active_plugins_keys = get_option( 'active_plugins', array() );
|
||||
$active_plugins = array();
|
||||
|
||||
|
||||
@@ -997,11 +997,9 @@ class WC_Webhook extends WC_Legacy_Webhook {
|
||||
),
|
||||
'order.deleted' => array(
|
||||
'wp_trash_post',
|
||||
'woocommerce_trash_order',
|
||||
),
|
||||
'order.restored' => array(
|
||||
'untrashed_post',
|
||||
'woocommerce_untrash_order',
|
||||
),
|
||||
'product.created' => array(
|
||||
'woocommerce_process_product_meta',
|
||||
|
||||
@@ -33,7 +33,7 @@ final class WooCommerce {
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $version = '8.1.1';
|
||||
public $version = '8.0.1';
|
||||
|
||||
/**
|
||||
* WooCommerce Schema version.
|
||||
|
||||
@@ -706,7 +706,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
*
|
||||
* @param WC_Abstract_Order $order Order object.
|
||||
*/
|
||||
protected function update_order_meta_from_object( $order ) {
|
||||
private function update_order_meta_from_object( $order ) {
|
||||
if ( is_null( $order->get_meta() ) ) {
|
||||
return;
|
||||
}
|
||||
@@ -715,24 +715,13 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
|
||||
foreach ( $order->get_meta_data() as $meta_data ) {
|
||||
if ( isset( $existing_meta_data[ $meta_data->key ] ) ) {
|
||||
// We don't know if the meta is single or array, so we assume it to be an array.
|
||||
$meta_value = is_array( $meta_data->value ) ? $meta_data->value : array( $meta_data->value );
|
||||
|
||||
if ( $existing_meta_data[ $meta_data->key ] === $meta_value ) {
|
||||
if ( $existing_meta_data[ $meta_data->key ] === $meta_data->value ) {
|
||||
unset( $existing_meta_data[ $meta_data->key ] );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( is_array( $existing_meta_data[ $meta_data->key ] ) ) {
|
||||
$value_index = array_search( $meta_data->value, $existing_meta_data[ $meta_data->key ], true );
|
||||
if ( false !== $value_index ) {
|
||||
unset( $existing_meta_data[ $meta_data->key ][ $value_index ] );
|
||||
if ( 0 === count( $existing_meta_data[ $meta_data->key ] ) ) {
|
||||
unset( $existing_meta_data[ $meta_data->key ] );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
unset( $existing_meta_data[ $meta_data->key ] );
|
||||
delete_post_meta( $order->get_id(), $meta_data->key );
|
||||
}
|
||||
add_post_meta( $order->get_id(), $meta_data->key, $meta_data->value, false );
|
||||
}
|
||||
@@ -746,11 +735,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
);
|
||||
|
||||
foreach ( $keys_to_delete as $meta_key ) {
|
||||
if ( isset( $existing_meta_data[ $meta_key ] ) ) {
|
||||
foreach ( $existing_meta_data[ $meta_key ] as $meta_value ) {
|
||||
delete_post_meta( $order->get_id(), $meta_key, maybe_unserialize( $meta_value ) );
|
||||
}
|
||||
}
|
||||
delete_post_meta( $order->get_id(), $meta_key );
|
||||
}
|
||||
|
||||
$this->update_post_meta( $order );
|
||||
|
||||
@@ -203,7 +203,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
$changes = $product->get_changes();
|
||||
|
||||
// Only update the post when the post data changes.
|
||||
if ( array_intersect( array( 'description', 'short_description', 'name', 'parent_id', 'reviews_allowed', 'status', 'menu_order', 'date_created', 'date_modified', 'slug', 'post_password' ), array_keys( $changes ) ) ) {
|
||||
if ( array_intersect( array( 'description', 'short_description', 'name', 'parent_id', 'reviews_allowed', 'status', 'menu_order', 'date_created', 'date_modified', 'slug' ), array_keys( $changes ) ) ) {
|
||||
$post_data = array(
|
||||
'post_content' => $product->get_description( 'edit' ),
|
||||
'post_excerpt' => $product->get_short_description( 'edit' ),
|
||||
|
||||
@@ -590,35 +590,6 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse dates from a CSV.
|
||||
* Dates can be Unix timestamps or in any format supported by strtotime().
|
||||
*
|
||||
* @param string $value Field value.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function parse_datetime_field( $value ) {
|
||||
try {
|
||||
// If value is a Unix timestamp, convert it to a datetime string.
|
||||
if ( is_numeric( $value ) ) {
|
||||
$datetime = new DateTime( "@{$value}" );
|
||||
// Return datetime string in ISO8601 format (eg. 2018-01-01T00:00:00Z) to preserve UTC timezone since Unix timestamps are always UTC.
|
||||
return $datetime->format( 'Y-m-d\TH:i:s\Z' );
|
||||
}
|
||||
// Check whether the value is a valid date string.
|
||||
if ( false !== strtotime( $value ) ) {
|
||||
// If the value is a valid date string, return as is.
|
||||
return $value;
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
// DateTime constructor throws an exception if the value is not a valid Unix timestamp.
|
||||
return null;
|
||||
}
|
||||
// If value is not valid Unix timestamp or date string, return null.
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse backorders from a CSV.
|
||||
*
|
||||
@@ -754,8 +725,8 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
||||
'type' => array( $this, 'parse_comma_field' ),
|
||||
'published' => array( $this, 'parse_published_field' ),
|
||||
'featured' => array( $this, 'parse_bool_field' ),
|
||||
'date_on_sale_from' => array( $this, 'parse_datetime_field' ),
|
||||
'date_on_sale_to' => array( $this, 'parse_datetime_field' ),
|
||||
'date_on_sale_from' => array( $this, 'parse_date_field' ),
|
||||
'date_on_sale_to' => array( $this, 'parse_date_field' ),
|
||||
'name' => array( $this, 'parse_skip_field' ),
|
||||
'short_description' => array( $this, 'parse_description_field' ),
|
||||
'description' => array( $this, 'parse_description_field' ),
|
||||
|
||||
@@ -9,7 +9,6 @@ if ( ! function_exists( 'wc_admin_get_feature_config' ) ) {
|
||||
'product-block-editor' => true,
|
||||
'coupons' => true,
|
||||
'core-profiler' => true,
|
||||
'customize-store' => false,
|
||||
'customer-effort-score-tracks' => true,
|
||||
'import-products-task' => true,
|
||||
'experimental-fashion-sample-products' => true,
|
||||
|
||||
@@ -81,22 +81,7 @@ class WC_REST_Telemetry_Controller extends WC_REST_Controller {
|
||||
}
|
||||
|
||||
$platform = $new['platform'];
|
||||
|
||||
if ( isset( $data[ $platform ] ) ) {
|
||||
$existing_usage = $data[ $platform ];
|
||||
|
||||
// Sets the installation date only if it has not been set before.
|
||||
if ( isset( $new['installation_date'] ) && ! isset( $existing_usage['installation_date'] ) ) {
|
||||
$data[ $platform ]['installation_date'] = $new['installation_date'];
|
||||
}
|
||||
|
||||
if ( version_compare( $new['version'], $existing_usage['version'], '>=' ) ) {
|
||||
$data[ $platform ]['version'] = $new['version'];
|
||||
$data[ $platform ]['last_used'] = $new['last_used'];
|
||||
}
|
||||
} else {
|
||||
// Only sets `first_used` when the platform usage data hasn't been set before.
|
||||
$new['first_used'] = $new['last_used'];
|
||||
if ( ! $data[ $platform ] || version_compare( $new['version'], $data[ $platform ]['version'], '>=' ) ) {
|
||||
$data[ $platform ] = $new;
|
||||
}
|
||||
|
||||
@@ -124,19 +109,10 @@ class WC_REST_Telemetry_Controller extends WC_REST_Controller {
|
||||
return;
|
||||
}
|
||||
|
||||
// The installation date could be null from earlier mobile client versions.
|
||||
$installation_date = $request->get_param( 'installation_date' );
|
||||
|
||||
return array_filter(
|
||||
array(
|
||||
'platform' => sanitize_text_field( $platform ),
|
||||
'version' => sanitize_text_field( $version ),
|
||||
'last_used' => gmdate( 'c' ),
|
||||
'installation_date' => isset( $installation_date ) ? get_gmt_from_date( $installation_date, 'c' ) : null,
|
||||
),
|
||||
function( $value ) {
|
||||
return null !== $value;
|
||||
}
|
||||
return array(
|
||||
'platform' => sanitize_text_field( $platform ),
|
||||
'version' => sanitize_text_field( $version ),
|
||||
'last_used' => gmdate( 'c' ),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -147,27 +123,20 @@ class WC_REST_Telemetry_Controller extends WC_REST_Controller {
|
||||
*/
|
||||
public function get_collection_params() {
|
||||
return array(
|
||||
'platform' => array(
|
||||
'platform' => array(
|
||||
'description' => __( 'Platform to track.', 'woocommerce' ),
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'version' => array(
|
||||
'version' => array(
|
||||
'description' => __( 'Platform version to track.', 'woocommerce' ),
|
||||
'required' => true,
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'installation_date' => array(
|
||||
'description' => __( 'Installation date of the WooCommerce mobile app.', 'woocommerce' ),
|
||||
'required' => false, // For backward compatibility.
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,10 +44,6 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
|
||||
'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
'delete' => array(
|
||||
'description' => __( 'Deletes unused variations.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
@@ -930,40 +926,6 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all unmatched variations (aka duplicates).
|
||||
*
|
||||
* @param WC_Product $product Variable product.
|
||||
* @return int Number of deleted variations.
|
||||
*/
|
||||
private function delete_unmatched_product_variations( $product ) {
|
||||
$deleted_count = 0;
|
||||
|
||||
if ( ! $product ) {
|
||||
return $deleted_count;
|
||||
}
|
||||
|
||||
$attributes = wc_list_pluck( array_filter( $product->get_attributes(), 'wc_attributes_array_filter_variation' ), 'get_slugs' );
|
||||
|
||||
// Get existing variations so we don't create duplicates.
|
||||
$existing_variations = array_map( 'wc_get_product', $product->get_children() );
|
||||
|
||||
$possible_attribute_combinations = array_reverse( wc_array_cartesian( $attributes ) );
|
||||
|
||||
foreach ( $existing_variations as $existing_variation ) {
|
||||
$matching_attribute_key = array_search( $existing_variation->get_attributes(), $possible_attribute_combinations ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
|
||||
if ( $matching_attribute_key !== false ) {
|
||||
// We only want one possible variation for each possible attribute combination.
|
||||
unset( $possible_attribute_combinations[ $matching_attribute_key ] );
|
||||
continue;
|
||||
}
|
||||
$existing_variation->delete( true );
|
||||
$deleted_count ++;
|
||||
}
|
||||
|
||||
return $deleted_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate all variations for a given product.
|
||||
*
|
||||
@@ -985,11 +947,6 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
|
||||
$data_store = $product->get_data_store();
|
||||
$response['count'] = $data_store->create_all_product_variations( $product, Constants::get_constant( 'WC_MAX_LINKED_VARIATIONS' ) );
|
||||
|
||||
if ( isset( $request['delete'] ) && $request['delete'] ) {
|
||||
$deleted_count = $this->delete_unmatched_product_variations( $product );
|
||||
$response['deleted_count'] = $deleted_count;
|
||||
}
|
||||
|
||||
$data_store->sort_all_product_variations( $product->get_id() );
|
||||
|
||||
return rest_ensure_response( $response );
|
||||
|
||||
@@ -432,11 +432,6 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
|
||||
$product->set_reviews_allowed( $request['reviews_allowed'] );
|
||||
}
|
||||
|
||||
// Post password.
|
||||
if ( isset( $request['post_password'] ) ) {
|
||||
$product->set_post_password( $request['post_password'] );
|
||||
}
|
||||
|
||||
// Virtual.
|
||||
if ( isset( $request['virtual'] ) ) {
|
||||
$product->set_virtual( $request['virtual'] );
|
||||
@@ -1145,11 +1140,6 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
|
||||
'default' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'post_password' => array(
|
||||
'description' => __( 'Post password.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'average_rating' => array(
|
||||
'description' => __( 'Reviews average rating.', 'woocommerce' ),
|
||||
'type' => 'string',
|
||||
@@ -1506,10 +1496,6 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
|
||||
$data['has_options'] = $product->has_options( $context );
|
||||
}
|
||||
|
||||
if ( in_array( 'post_password', $fields, true ) ) {
|
||||
$data['post_password'] = $product->get_post_password( $context );
|
||||
}
|
||||
|
||||
$post_type_obj = get_post_type_object( $this->post_type );
|
||||
if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) {
|
||||
$permalink_template_requested = in_array( 'permalink_template', $fields, true );
|
||||
|
||||
@@ -162,11 +162,12 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
|
||||
if ( in_array( $this->requires, array( 'min_amount', 'either', 'both' ), true ) ) {
|
||||
$total = WC()->cart->get_displayed_subtotal();
|
||||
|
||||
if ( WC()->cart->display_prices_including_tax() ) {
|
||||
$total = $total - WC()->cart->get_discount_tax();
|
||||
}
|
||||
|
||||
if ( 'no' === $this->ignore_discounts ) {
|
||||
$total = $total - WC()->cart->get_discount_total();
|
||||
if ( WC()->cart->display_prices_including_tax() ) {
|
||||
$total = $total - WC()->cart->get_discount_tax();
|
||||
}
|
||||
}
|
||||
|
||||
$total = NumberUtil::round( $total, wc_get_price_decimals() );
|
||||
|
||||
@@ -301,7 +301,6 @@ class WC_Shortcode_Checkout {
|
||||
|
||||
// For non-guest orders, require the user to be logged in before showing this page.
|
||||
if ( $order_customer_id && get_current_user_id() !== $order_customer_id ) {
|
||||
wc_get_template( 'checkout/order-received.php', array( 'order' => false ) );
|
||||
wc_print_notice( esc_html__( 'Please log in to your account to view this order.', 'woocommerce' ), 'notice' );
|
||||
woocommerce_login_form( array( 'redirect' => $order->get_checkout_order_received_url() ) );
|
||||
return;
|
||||
@@ -309,7 +308,6 @@ class WC_Shortcode_Checkout {
|
||||
|
||||
// For guest orders, request they verify their email address (unless we can identify them via the active user session).
|
||||
if ( self::guest_should_verify_email( $order, 'order-received' ) ) {
|
||||
wc_get_template( 'checkout/order-received.php', array( 'order' => false ) );
|
||||
wc_get_template(
|
||||
'checkout/form-verify-email.php',
|
||||
array(
|
||||
@@ -387,9 +385,8 @@ class WC_Shortcode_Checkout {
|
||||
return false;
|
||||
}
|
||||
|
||||
$email = filter_input( INPUT_POST, 'email' );
|
||||
$nonce = filter_input( INPUT_POST, 'check_submission' );
|
||||
if ( $email && ! wp_verify_nonce( $nonce, 'wc_verify_email' ) ) {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
if ( ! empty( $_POST ) && ! wp_verify_nonce( $_POST['check_submission'] ?? '', 'wc_verify_email' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ defined( 'ABSPATH' ) || exit;
|
||||
use Automattic\WooCommerce\Database\Migrations\MigrationHelper;
|
||||
use Automattic\WooCommerce\Internal\Admin\Marketing\MarketingSpecs;
|
||||
use Automattic\WooCommerce\Internal\AssignDefaultCategory;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
|
||||
use Automattic\WooCommerce\Internal\ProductAttributesLookup\DataRegenerator;
|
||||
use Automattic\WooCommerce\Internal\ProductAttributesLookup\LookupDataStore;
|
||||
@@ -2592,50 +2591,3 @@ function wc_update_770_remove_multichannel_marketing_feature_options() {
|
||||
delete_option( 'woocommerce_multichannel_marketing_enabled' );
|
||||
delete_option( 'woocommerce_marketing_overview_welcome_hidden' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrate transaction data which was being incorrectly stored in the postmeta table to HPOS tables.
|
||||
*
|
||||
* @return bool Whether there are pending migration recrods.
|
||||
*/
|
||||
function wc_update_810_migrate_transactional_metadata_for_hpos() {
|
||||
global $wpdb;
|
||||
|
||||
$data_synchronizer = wc_get_container()->get( DataSynchronizer::class );
|
||||
if ( ! $data_synchronizer->get_table_exists() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$orders_table = OrdersTableDataStore::get_orders_table_name();
|
||||
$orders_meta_table = OrdersTableDataStore::get_meta_table_name();
|
||||
|
||||
/**
|
||||
* We are migrating payment_tokens meta that is stored in wp_postmeta table to the HPOS table. To do this with minimum db ops:
|
||||
* 1. We join postmeta table with wc_orders table directly, this filters out orders that are yet to be migrated and any post with non-order post type.
|
||||
* 2. A combination of filter on wc_orders_meta.meta_key = _payment_tokens in the join condition itself, along with a null check in a WHERE condition, allows us to only get the orders where the meta is not yet migrated.
|
||||
*/
|
||||
$select_query = "
|
||||
SELECT post_id, '_payment_tokens', {$wpdb->postmeta}.meta_value
|
||||
FROM {$wpdb->postmeta}
|
||||
JOIN $orders_table ON {$wpdb->postmeta}.post_id = $orders_table.id
|
||||
LEFT JOIN $orders_meta_table ON $orders_meta_table.order_id = $orders_table.id AND $orders_meta_table.meta_key = '_payment_tokens'
|
||||
WHERE
|
||||
{$wpdb->postmeta}.meta_key = '_payment_tokens'
|
||||
AND $orders_meta_table.order_id IS NULL
|
||||
";
|
||||
|
||||
// No need to get the data in application, we can insert directly. Sync setting does not matter as this data already exist in the post table. Limit the batch size to 250.
|
||||
$query =
|
||||
"
|
||||
INSERT INTO $orders_meta_table (order_id, meta_key, meta_value)
|
||||
$select_query
|
||||
LIMIT 250
|
||||
";
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No user input in the query, everything hardcoded.
|
||||
$wpdb->query( $query );
|
||||
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- No user input in the query, everything hardcoded.
|
||||
$has_pending = $wpdb->query( "$select_query LIMIT 1;" );
|
||||
|
||||
return ! empty( $has_pending );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user