plugin updates
This commit is contained in:
@@ -118,7 +118,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||
throw new Exception( __( 'Invalid coupon.', 'woocommerce' ) );
|
||||
}
|
||||
|
||||
$coupon_id = $coupon->get_id();
|
||||
$coupon_id = $coupon->get_id();
|
||||
$limit_usage_to_x_items = get_post_meta( $coupon_id, 'limit_usage_to_x_items', true );
|
||||
$coupon->set_props(
|
||||
array(
|
||||
'code' => $post_object->post_title,
|
||||
@@ -131,11 +132,11 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||
'amount' => get_post_meta( $coupon_id, 'coupon_amount', true ),
|
||||
'usage_count' => get_post_meta( $coupon_id, 'usage_count', true ),
|
||||
'individual_use' => 'yes' === get_post_meta( $coupon_id, 'individual_use', true ),
|
||||
'product_ids' => array_filter( (array) explode( ',', get_post_meta( $coupon_id, 'product_ids', true ) ) ),
|
||||
'excluded_product_ids' => array_filter( (array) explode( ',', get_post_meta( $coupon_id, 'exclude_product_ids', true ) ) ),
|
||||
'product_ids' => $this->get_coupon_meta_as_array( $coupon_id, 'product_ids' ),
|
||||
'excluded_product_ids' => $this->get_coupon_meta_as_array( $coupon_id, 'exclude_product_ids' ),
|
||||
'usage_limit' => get_post_meta( $coupon_id, 'usage_limit', true ),
|
||||
'usage_limit_per_user' => get_post_meta( $coupon_id, 'usage_limit_per_user', true ),
|
||||
'limit_usage_to_x_items' => 0 < get_post_meta( $coupon_id, 'limit_usage_to_x_items', true ) ? get_post_meta( $coupon_id, 'limit_usage_to_x_items', true ) : null,
|
||||
'limit_usage_to_x_items' => $limit_usage_to_x_items > 0 ? $limit_usage_to_x_items : null,
|
||||
'free_shipping' => 'yes' === get_post_meta( $coupon_id, 'free_shipping', true ),
|
||||
'product_categories' => array_filter( (array) get_post_meta( $coupon_id, 'product_categories', true ) ),
|
||||
'excluded_product_categories' => array_filter( (array) get_post_meta( $coupon_id, 'exclude_product_categories', true ) ),
|
||||
@@ -151,6 +152,24 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||
do_action( 'woocommerce_coupon_loaded', $coupon );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a metadata value that is stored as either a string consisting of a comma-separated list of values
|
||||
* or as a serialized array.
|
||||
*
|
||||
* WooCommerce always stores the coupon product ids as a comma-separated string, but it seems that
|
||||
* some plugins mistakenly change these to an array.
|
||||
*
|
||||
* @param int $coupon_id The coupon id.
|
||||
* @param string $meta_key The meta key to get.
|
||||
* @return array The metadata value as an array, with empty values removed.
|
||||
*/
|
||||
private function get_coupon_meta_as_array( $coupon_id, string $meta_key ) {
|
||||
$meta_value = get_post_meta( $coupon_id, $meta_key, true );
|
||||
return array_filter(
|
||||
is_array( $meta_value ) ? $meta_value : explode( ',', $meta_value )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a coupon in the database.
|
||||
*
|
||||
@@ -190,6 +209,12 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||
$this->update_post_meta( $coupon );
|
||||
$coupon->apply_changes();
|
||||
delete_transient( 'rest_api_coupons_type_count' );
|
||||
|
||||
// The `coupon_id_from_code` entry in the object cache must not exist when the coupon is not published, otherwise the coupon will remain available for use.
|
||||
if ( 'publish' !== $coupon->get_status() ) {
|
||||
wp_cache_delete( WC_Cache_Helper::get_cache_prefix( 'coupons' ) . 'coupon_id_from_code_' . $coupon->get_code(), 'coupons' );
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_update_coupon', $coupon->get_id(), $coupon );
|
||||
}
|
||||
|
||||
@@ -440,7 +465,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||
*/
|
||||
public function get_usage_by_user_id( &$coupon, $user_id ) {
|
||||
global $wpdb;
|
||||
$usage_count = $wpdb->get_var(
|
||||
$usage_count = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT COUNT( meta_id ) FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_used_by' AND meta_value = %s;",
|
||||
$coupon->get_id(),
|
||||
@@ -461,7 +486,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||
*/
|
||||
public function get_usage_by_email( &$coupon, $email ) {
|
||||
global $wpdb;
|
||||
$usage_count = $wpdb->get_var(
|
||||
$usage_count = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT COUNT( meta_id ) FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_used_by' AND meta_value = %s;",
|
||||
$coupon->get_id(),
|
||||
@@ -485,7 +510,6 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||
return $wpdb->get_var(
|
||||
$this->get_tentative_usage_query_for_user( $coupon_id, $user_aliases )
|
||||
); // WPCS: unprepared SQL ok.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -637,8 +661,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||
$query_for_tentative_usages = $this->get_tentative_usage_query_for_user( $coupon->get_id(), $user_aliases );
|
||||
$db_timestamp = $wpdb->get_var( 'SELECT UNIX_TIMESTAMP() FROM ' . $wpdb->posts . ' LIMIT 1' );
|
||||
|
||||
$coupon_used_by_meta_key = '_maybe_used_by_' . ( (int) $db_timestamp + $held_time ) . '_' . wp_generate_password( 6, false );
|
||||
$insert_statement = $wpdb->prepare(
|
||||
$coupon_used_by_meta_key = '_maybe_used_by_' . ( (int) $db_timestamp + $held_time ) . '_' . wp_generate_password( 6, false );
|
||||
$insert_statement = $wpdb->prepare(
|
||||
"
|
||||
INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value )
|
||||
SELECT %d, %s, %s FROM $wpdb->posts
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
|
||||
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
|
||||
use Automattic\WooCommerce\Internal\Utilities\Users;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
@@ -340,17 +341,36 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||
* @return WC_Order|false
|
||||
*/
|
||||
public function get_last_order( &$customer ) {
|
||||
//phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
|
||||
// Try to fetch the last order placed by this customer.
|
||||
$last_order_id = Users::get_site_user_meta( $customer->get_id(), 'wc_last_order', true );
|
||||
$last_customer_order = false;
|
||||
|
||||
if ( ! empty( $last_order_id ) ) {
|
||||
$last_customer_order = wc_get_order( $last_order_id );
|
||||
}
|
||||
|
||||
// "Unset" the last order ID if the order is associated with another customer. Unsetting is done by making it an
|
||||
// empty string, for compatibility with the declared types of the following filter hook.
|
||||
if (
|
||||
! $last_customer_order instanceof WC_Order
|
||||
|| intval( $last_customer_order->get_customer_id() ) !== intval( $customer->get_id() )
|
||||
) {
|
||||
$last_order_id = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the id of the last order from a given customer.
|
||||
*
|
||||
* @param string @last_order_id The last order id as retrieved from the database.
|
||||
* @param WC_Customer The customer whose last order id is being retrieved.
|
||||
* @since 4.9.1
|
||||
*
|
||||
* @param string $last_order_id The last order id as retrieved from the database.
|
||||
* @param WC_Customer $customer The customer whose last order id is being retrieved.
|
||||
*
|
||||
* @return string The actual last order id to use.
|
||||
*/
|
||||
$last_order_id = apply_filters(
|
||||
'woocommerce_customer_get_last_order',
|
||||
get_user_meta( $customer->get_id(), '_last_order', true ),
|
||||
$last_order_id,
|
||||
$customer
|
||||
);
|
||||
//phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment
|
||||
@@ -385,7 +405,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||
);
|
||||
}
|
||||
//phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
update_user_meta( $customer->get_id(), '_last_order', $last_order_id );
|
||||
Users::update_site_user_meta( $customer->get_id(), 'wc_last_order', $last_order_id );
|
||||
}
|
||||
|
||||
if ( ! $last_order_id ) {
|
||||
@@ -405,7 +425,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||
public function get_order_count( &$customer ) {
|
||||
$count = apply_filters(
|
||||
'woocommerce_customer_get_order_count',
|
||||
get_user_meta( $customer->get_id(), '_order_count', true ),
|
||||
Users::get_site_user_meta( $customer->get_id(), 'wc_order_count', true ),
|
||||
$customer
|
||||
);
|
||||
|
||||
@@ -436,7 +456,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||
}
|
||||
//phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
|
||||
update_user_meta( $customer->get_id(), '_order_count', $count );
|
||||
Users::update_site_user_meta( $customer->get_id(), 'wc_order_count', $count );
|
||||
}
|
||||
|
||||
return absint( $count );
|
||||
@@ -452,7 +472,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||
public function get_total_spent( &$customer ) {
|
||||
$spent = apply_filters(
|
||||
'woocommerce_customer_get_total_spent',
|
||||
get_user_meta( $customer->get_id(), '_money_spent', true ),
|
||||
Users::get_site_user_meta( $customer->get_id(), 'wc_money_spent', true ),
|
||||
$customer
|
||||
);
|
||||
|
||||
@@ -499,7 +519,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
|
||||
if ( ! $spent ) {
|
||||
$spent = 0;
|
||||
}
|
||||
update_user_meta( $customer->get_id(), '_money_spent', $spent );
|
||||
Users::update_site_user_meta( $customer->get_id(), 'wc_money_spent', $spent );
|
||||
}
|
||||
|
||||
return wc_format_decimal( $spent, 2 );
|
||||
|
||||
@@ -138,6 +138,12 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
if ( $id && ! is_wp_error( $id ) ) {
|
||||
$product->set_id( $id );
|
||||
|
||||
// get the post object so that we can set the status
|
||||
// to the correct value; it is possible that the status was
|
||||
// changed by the woocommerce_new_product_data filter above.
|
||||
$post_object = get_post( $product->get_id() );
|
||||
$product->set_status( $post_object->post_status );
|
||||
|
||||
$this->update_post_meta( $product, true );
|
||||
$this->update_terms( $product, true );
|
||||
$this->update_visibility( $product, true );
|
||||
@@ -272,7 +278,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
|
||||
$product->apply_changes();
|
||||
|
||||
do_action( 'woocommerce_update_product', $product->get_id(), $product );
|
||||
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
|
||||
do_action( 'woocommerce_update_product', $product->get_id(), $product, $changes );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1236,7 +1243,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
||||
|
||||
do_action( 'product_variation_linked', $variation_id );
|
||||
|
||||
$count ++;
|
||||
++$count;
|
||||
|
||||
if ( $limit > 0 && $count >= $limit ) {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user