auto-patch 638-dev-dev01-2024-05-14T20_44_36
This commit is contained in:
@@ -12,6 +12,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// phpcs:disable Squiz.Classes.ClassFileName.NoMatch, Squiz.Classes.ValidClassName.NotCamelCaps -- Backward compatibility.
|
||||
/**
|
||||
* Abstract Order Data Store: Stored in CPT.
|
||||
*
|
||||
@@ -80,6 +81,13 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
}
|
||||
|
||||
$id = wp_insert_post(
|
||||
/**
|
||||
* Filters the data for a new order before it is inserted into the database.
|
||||
*
|
||||
* @param array $data Array of data for the new order.
|
||||
*
|
||||
* @since 3.3.0
|
||||
*/
|
||||
apply_filters(
|
||||
'woocommerce_new_order_data',
|
||||
array(
|
||||
@@ -115,7 +123,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
* @param int $order_id The order id to check.
|
||||
* @return bool True if an order exists with the given name.
|
||||
*/
|
||||
public function order_exists( $order_id ) : bool {
|
||||
public function order_exists( $order_id ): bool {
|
||||
if ( ! $order_id ) {
|
||||
return false;
|
||||
}
|
||||
@@ -135,7 +143,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
$order->set_defaults();
|
||||
$post_object = get_post( $order->get_id() );
|
||||
if ( ! $order->get_id() || ! $post_object || ! in_array( $post_object->post_type, wc_get_order_types(), true ) ) {
|
||||
throw new Exception( __( 'Invalid order.', 'woocommerce' ) );
|
||||
throw new Exception( esc_html__( 'Invalid order.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
$this->set_order_props(
|
||||
@@ -291,7 +299,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
/**
|
||||
* Fires immediately after an order is deleted.
|
||||
*
|
||||
* @since
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @param int $order_id ID of the order that has been deleted.
|
||||
*/
|
||||
@@ -317,7 +325,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
/**
|
||||
* Fires immediately after an order is trashed.
|
||||
*
|
||||
* @since
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @param int $order_id ID of the order that has been trashed.
|
||||
*/
|
||||
@@ -345,6 +353,13 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
$order_status = $order->get_status( 'edit' );
|
||||
|
||||
if ( ! $order_status ) {
|
||||
/**
|
||||
* Filters the default order status to use when creating a new order.
|
||||
*
|
||||
* @param string $order_status Default order status.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
$order_status = apply_filters( 'woocommerce_default_order_status', 'pending' );
|
||||
}
|
||||
|
||||
@@ -352,7 +367,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
$valid_statuses = get_post_stati();
|
||||
|
||||
// Add a wc- prefix to the status, but exclude some core statuses which should not be prefixed.
|
||||
// @todo In the future this should only happen based on `wc_is_order_status`, but in order to
|
||||
// In the future this should only happen based on `wc_is_order_status`, but in order to
|
||||
// preserve back-compatibility this happens to all statuses except a select few. A doing_it_wrong
|
||||
// Notice will be needed here, followed by future removal.
|
||||
if ( ! in_array( $post_status, array( 'auto-draft', 'draft', 'trash' ), true ) && in_array( 'wc-' . $post_status, $valid_statuses, true ) ) {
|
||||
@@ -380,7 +395,7 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
protected function get_post_title() {
|
||||
// @codingStandardsIgnoreStart
|
||||
/* translators: %s: Order date */
|
||||
return sprintf( __( 'Order – %s', 'woocommerce' ), (new DateTime('now'))->format( _x( 'M d, Y @ h:i A', 'Order date parsed by DateTime::format', 'woocommerce' ) ) );
|
||||
return sprintf( __( 'Order – %s', 'woocommerce' ), ( new DateTime( 'now' ) )->format( _x( 'M d, Y @ h:i A', 'Order date parsed by DateTime::format', 'woocommerce' ) ) );
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
|
||||
@@ -466,6 +481,14 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action fired after updating order properties.
|
||||
*
|
||||
* @param WC_Abstract_Order $order Order object.
|
||||
* @param string[] $updated_props Array of updated properties.
|
||||
*
|
||||
* @since 2.7.0
|
||||
*/
|
||||
do_action( 'woocommerce_order_object_updated_props', $order, $updated_props );
|
||||
}
|
||||
|
||||
@@ -491,6 +514,11 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
|
||||
public function read_items( $order, $type ) {
|
||||
global $wpdb;
|
||||
|
||||
// When the order is not yet saved, we cannot get the items from DB. Trying to do so will risk reading items of different orders that were saved incorrectly.
|
||||
if ( 0 === $order->get_id() ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Get from cache if available.
|
||||
$items = 0 < $order->get_id() ? wp_cache_get( 'order-items-' . $order->get_id(), 'orders' ) : false;
|
||||
|
||||
|
||||
@@ -95,14 +95,24 @@ class WC_Customer_Data_Store_Session extends WC_Data_Store_WP implements WC_Cust
|
||||
* @param WC_Customer $customer The customer object.
|
||||
*/
|
||||
$allowed_keys = apply_filters( 'woocommerce_customer_allowed_session_meta_keys', array(), $customer );
|
||||
$session_value = wp_json_encode(
|
||||
array_filter(
|
||||
$customer->get_meta_data(),
|
||||
function( $meta_data ) use ( $allowed_keys ) {
|
||||
return in_array( $meta_data->key, $allowed_keys, true );
|
||||
}
|
||||
$session_value = maybe_serialize(
|
||||
array_map(
|
||||
function ( $meta_data ) {
|
||||
// Data comes to us a WC_Meta_Data, we cast it to an array to ensure it is serializable.
|
||||
return array(
|
||||
'key' => $meta_data->key,
|
||||
'value' => $meta_data->value,
|
||||
);
|
||||
},
|
||||
array_filter(
|
||||
$customer->get_meta_data(),
|
||||
function ( $meta_data ) use ( $allowed_keys ) {
|
||||
return in_array( $meta_data->key, $allowed_keys, true );
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
$session_value = $customer->{"get_$function_key"}( 'edit' );
|
||||
}
|
||||
@@ -137,7 +147,7 @@ class WC_Customer_Data_Store_Session extends WC_Data_Store_WP implements WC_Cust
|
||||
}
|
||||
if ( ! empty( $data[ $session_key ] ) && is_callable( array( $customer, "set_{$function_key}" ) ) ) {
|
||||
if ( 'meta_data' === $session_key ) {
|
||||
$meta_data_values = json_decode( wp_unslash( $data[ $session_key ] ), true );
|
||||
$meta_data_values = maybe_unserialize( $data[ $session_key ] );
|
||||
if ( $meta_data_values ) {
|
||||
foreach ( $meta_data_values as $meta_data_value ) {
|
||||
if ( ! isset( $meta_data_value['key'], $meta_data_value['value'] ) ) {
|
||||
|
||||
@@ -1099,6 +1099,11 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
* @return int Matching variation ID or 0.
|
||||
*/
|
||||
public function find_matching_product_variation( $product, $match_attributes = array() ) {
|
||||
if ( 'variation' === $product->get_type() ) {
|
||||
// Can't get a variation of a variation.
|
||||
return 0;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$meta_attribute_names = array();
|
||||
@@ -1188,10 +1193,11 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
* @todo Add to interface in 4.0.
|
||||
* @param WC_Product $product Variable product.
|
||||
* @param int $limit Limit the number of created variations.
|
||||
* @param array $default_values Key value pairs to set on created variations.
|
||||
* @param array $default_values Key value pairs to set on created variations.
|
||||
* @param array $metadata Key value pairs to set as meta data on created variations.
|
||||
* @return int Number of created variations.
|
||||
*/
|
||||
public function create_all_product_variations( $product, $limit = -1, $default_values = array() ) {
|
||||
public function create_all_product_variations( $product, $limit = -1, $default_values = array(), $metadata = array() ) {
|
||||
$count = 0;
|
||||
|
||||
if ( ! $product ) {
|
||||
@@ -1221,6 +1227,9 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
}
|
||||
$variation = wc_get_product_object( 'variation' );
|
||||
$variation->set_props( $default_values );
|
||||
foreach ( $metadata as $meta ) {
|
||||
$variation->add_meta_data( $meta['key'], $meta['value'] );
|
||||
}
|
||||
$variation->set_parent_id( $product->get_id() );
|
||||
$variation->set_attributes( $possible_attribute );
|
||||
$variation_id = $variation->save();
|
||||
|
||||
Reference in New Issue
Block a user