typecast $used_by to array in case its not set. Closes #5350
This commit is contained in:
parent
da8015a49c
commit
a6a65a2a9d
|
@ -1487,7 +1487,7 @@ class WC_Cart {
|
|||
|
||||
// Usage limits per user - check against billing and user email and user ID
|
||||
if ( $coupon->usage_limit_per_user > 0 ) {
|
||||
$used_by = get_post_meta( $this->id, '_used_by' );
|
||||
$used_by = (array) get_post_meta( $this->id, '_used_by' );
|
||||
|
||||
if ( is_user_logged_in() ) {
|
||||
$current_user = wp_get_current_user();
|
||||
|
@ -1495,11 +1495,11 @@ class WC_Cart {
|
|||
}
|
||||
$check_emails[] = $posted['billing_email'];
|
||||
$check_emails = array_map( 'sanitize_email', array_map( 'strtolower', $check_emails ) );
|
||||
|
||||
$usage_count = sizeof( array_keys( $used_by, get_current_user_id() ) );
|
||||
|
||||
foreach ( $check_emails as $check_email )
|
||||
foreach ( $check_emails as $check_email ) {
|
||||
$usage_count = $usage_count + sizeof( array_keys( $used_by, $check_email ) );
|
||||
}
|
||||
|
||||
if ( $usage_count >= $coupon->usage_limit_per_user ) {
|
||||
$coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_USAGE_LIMIT_REACHED );
|
||||
|
|
|
@ -229,8 +229,9 @@ class WC_Coupon {
|
|||
$this->usage_count++;
|
||||
update_post_meta( $this->id, 'usage_count', $this->usage_count );
|
||||
|
||||
if ( $used_by )
|
||||
if ( $used_by ) {
|
||||
add_post_meta( $this->id, '_used_by', strtolower( $used_by ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -249,8 +250,9 @@ class WC_Coupon {
|
|||
|
||||
// Delete 1 used by meta
|
||||
$meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_used_by' AND meta_value = %s AND post_id = %d LIMIT 1;", $used_by, $this->id ) );
|
||||
if ( $meta_id )
|
||||
if ( $meta_id ) {
|
||||
delete_metadata_by_mid( 'post', $meta_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -290,7 +292,7 @@ class WC_Coupon {
|
|||
// Per user usage limit - check here if user is logged in (against user IDs)
|
||||
// Checked again for emails later on in WC_Cart::check_customer_coupons()
|
||||
if ( $this->usage_limit_per_user > 0 && is_user_logged_in() ) {
|
||||
$used_by = get_post_meta( $this->id, '_used_by' );
|
||||
$used_by = (array) get_post_meta( $this->id, '_used_by' );
|
||||
$usage_count = sizeof( array_keys( $used_by, get_current_user_id() ) );
|
||||
|
||||
if ( $usage_count >= $this->usage_limit_per_user ) {
|
||||
|
|
Loading…
Reference in New Issue