Set coupon virtual state on when initializing virtual coupons during recalculation
This commit is contained in:
parent
961c190985
commit
3cd1bedade
|
@ -1005,6 +1005,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
$coupon_object = new WC_Coupon();
|
||||
$coupon_object->set_props( $original_coupon_data );
|
||||
$coupon_object->set_code( $coupon_code );
|
||||
$coupon_object->set_virtual( true );
|
||||
|
||||
// If there is no coupon amount (maybe dynamic?), set it to the given **discount** amount so the coupon's same value is applied.
|
||||
if ( ! $coupon_object->get_amount() ) {
|
||||
|
|
|
@ -46,6 +46,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
'maximum_amount' => '',
|
||||
'email_restrictions' => array(),
|
||||
'used_by' => array(),
|
||||
'virtual' => false,
|
||||
);
|
||||
|
||||
// Coupon message codes
|
||||
|
@ -73,13 +74,6 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
*/
|
||||
protected $cache_group = 'coupons';
|
||||
|
||||
/**
|
||||
* Is this coupon added through the woocommerce_get_shop_coupon_data filter?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_virtual = false;
|
||||
|
||||
/**
|
||||
* Coupon constructor. Loads coupon data.
|
||||
* @param mixed $data Coupon data, object, ID or code.
|
||||
|
@ -361,6 +355,17 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
return $this->get_prop( 'used_by', $context );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the filter is added through the woocommerce_get_shop_coupon_data filter, it's virtual and not in the DB.
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @param string $context
|
||||
* @return boolean
|
||||
*/
|
||||
public function get_virtual( $context = 'view' ) {
|
||||
return (bool) $this->get_prop( 'virtual', $context );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get discount amount for a cart item.
|
||||
*
|
||||
|
@ -649,6 +654,15 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
$this->set_prop( 'used_by', array_filter( $used_by ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set coupon virtual state.
|
||||
* @param boolean $virtual Whether it is virtual or not.
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function set_virtual( $virtual ) {
|
||||
$this->set_prop( 'virtual', (bool) $virtual );
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Other Actions
|
||||
|
@ -700,17 +714,7 @@ class WC_Coupon extends WC_Legacy_Coupon {
|
|||
$this->set_props( $coupon );
|
||||
$this->set_code( $code );
|
||||
$this->set_id( 0 );
|
||||
$this->is_virtual = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the filter is added through the woocommerce_get_shop_coupon_data filter, it's virtual and not in the DB.
|
||||
*
|
||||
* @since 3.2.0
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_virtual() {
|
||||
return (bool) $this->is_virtual;
|
||||
$this->set_virtual( true );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -497,7 +497,7 @@ class WC_Discounts {
|
|||
* @return bool
|
||||
*/
|
||||
protected function validate_coupon_exists( $coupon ) {
|
||||
if ( ! $coupon->get_id() && ! $coupon->is_virtual() ) {
|
||||
if ( ! $coupon->get_id() && ! $coupon->get_virtual() ) {
|
||||
/* translators: %s: coupon code */
|
||||
throw new Exception( sprintf( __( 'Coupon "%s" does not exist!', 'woocommerce' ), $coupon->get_code() ), 105 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue