parent
8baef77b5c
commit
1b5cad3d78
|
@ -37,7 +37,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
||||||
'excluded_product_ids' => array(),
|
'excluded_product_ids' => array(),
|
||||||
'usage_limit' => 0,
|
'usage_limit' => 0,
|
||||||
'usage_limit_per_user' => 0,
|
'usage_limit_per_user' => 0,
|
||||||
'limit_usage_to_x_items' => 0,
|
'limit_usage_to_x_items' => null,
|
||||||
'free_shipping' => false,
|
'free_shipping' => false,
|
||||||
'product_categories' => array(),
|
'product_categories' => array(),
|
||||||
'excluded_product_categories' => array(),
|
'excluded_product_categories' => array(),
|
||||||
|
@ -262,7 +262,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
||||||
* Usage limited to certain amount of items
|
* Usage limited to certain amount of items
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @param string $context
|
* @param string $context
|
||||||
* @return integer
|
* @return integer|null
|
||||||
*/
|
*/
|
||||||
public function get_limit_usage_to_x_items( $context = 'view' ) {
|
public function get_limit_usage_to_x_items( $context = 'view' ) {
|
||||||
return $this->get_prop( 'limit_usage_to_x_items', $context );
|
return $this->get_prop( 'limit_usage_to_x_items', $context );
|
||||||
|
@ -388,11 +388,12 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
||||||
// Handle the limit_usage_to_x_items option
|
// Handle the limit_usage_to_x_items option
|
||||||
if ( ! $this->is_type( array( 'fixed_cart' ) ) ) {
|
if ( ! $this->is_type( array( 'fixed_cart' ) ) ) {
|
||||||
if ( $discounting_amount ) {
|
if ( $discounting_amount ) {
|
||||||
if ( ! $this->get_limit_usage_to_x_items() ) {
|
if ( null === $this->get_limit_usage_to_x_items() ) {
|
||||||
$limit_usage_qty = $cart_item_qty;
|
$limit_usage_qty = $cart_item_qty;
|
||||||
} else {
|
} else {
|
||||||
$limit_usage_qty = min( $this->get_limit_usage_to_x_items(), $cart_item_qty );
|
$limit_usage_qty = min( $this->get_limit_usage_to_x_items(), $cart_item_qty );
|
||||||
$this->set_limit_usage_to_x_items( max( 0, $this->get_limit_usage_to_x_items() - $limit_usage_qty ) );
|
|
||||||
|
$this->set_limit_usage_to_x_items( max( 0, ( $this->get_limit_usage_to_x_items() - $limit_usage_qty ) ) );
|
||||||
}
|
}
|
||||||
if ( $single ) {
|
if ( $single ) {
|
||||||
$discount = ( $discount * $limit_usage_qty ) / $cart_item_qty;
|
$discount = ( $discount * $limit_usage_qty ) / $cart_item_qty;
|
||||||
|
@ -557,11 +558,11 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
||||||
/**
|
/**
|
||||||
* Set usage limit to x number of items.
|
* Set usage limit to x number of items.
|
||||||
* @since 3.0.0
|
* @since 3.0.0
|
||||||
* @param int $limit_usage_to_x_items
|
* @param int|null $limit_usage_to_x_items
|
||||||
* @throws WC_Data_Exception
|
* @throws WC_Data_Exception
|
||||||
*/
|
*/
|
||||||
public function set_limit_usage_to_x_items( $limit_usage_to_x_items ) {
|
public function set_limit_usage_to_x_items( $limit_usage_to_x_items ) {
|
||||||
$this->set_prop( 'limit_usage_to_x_items', absint( $limit_usage_to_x_items ) );
|
$this->set_prop( 'limit_usage_to_x_items', is_null( $limit_usage_to_x_items ) ? null : absint( $limit_usage_to_x_items ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1027,7 +1028,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
||||||
}
|
}
|
||||||
|
|
||||||
$valid = false;
|
$valid = false;
|
||||||
$product_cats = wc_get_product_cat_ids( $product->get_id() );
|
$product_cats = wc_get_product_cat_ids( $product->is_type( 'variation' ) ? $product->get_parent_id() : $product->get_id() );
|
||||||
$product_ids = array( $product->get_id(), $product->get_parent_id() );
|
$product_ids = array( $product->get_id(), $product->get_parent_id() );
|
||||||
|
|
||||||
// Specific products get the discount
|
// Specific products get the discount
|
||||||
|
|
|
@ -105,7 +105,7 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
|
||||||
'excluded_product_ids' => array_filter( (array) explode( ',', get_post_meta( $coupon_id, 'exclude_product_ids', true ) ) ),
|
'excluded_product_ids' => array_filter( (array) explode( ',', get_post_meta( $coupon_id, 'exclude_product_ids', true ) ) ),
|
||||||
'usage_limit' => get_post_meta( $coupon_id, 'usage_limit', true ),
|
'usage_limit' => get_post_meta( $coupon_id, 'usage_limit', true ),
|
||||||
'usage_limit_per_user' => get_post_meta( $coupon_id, 'usage_limit_per_user', true ),
|
'usage_limit_per_user' => get_post_meta( $coupon_id, 'usage_limit_per_user', true ),
|
||||||
'limit_usage_to_x_items' => get_post_meta( $coupon_id, 'limit_usage_to_x_items', 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,
|
||||||
'free_shipping' => 'yes' === get_post_meta( $coupon_id, 'free_shipping', true ),
|
'free_shipping' => 'yes' === get_post_meta( $coupon_id, 'free_shipping', true ),
|
||||||
'product_categories' => array_filter( (array) get_post_meta( $coupon_id, 'product_categories', 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 ) ),
|
'excluded_product_categories' => array_filter( (array) get_post_meta( $coupon_id, 'exclude_product_categories', true ) ),
|
||||||
|
|
Loading…
Reference in New Issue