Switched to property_exists and moved deprecation notice to avoid errors and setting fees unnecessarily.
This commit is contained in:
parent
feffde2a73
commit
803b31a18c
|
@ -1754,9 +1754,8 @@ class WC_Cart extends WC_Legacy_Cart {
|
|||
public function get_fees() {
|
||||
$fees = $this->fees_api()->get_fees();
|
||||
|
||||
if ( ! empty( $this->fees ) ) {
|
||||
wc_deprecated_function( 'WC_Cart->fees', '3.2', sprintf( 'Fees should only be added through the Fees API (%s)', 'WC_Cart::add_fee()' ) );
|
||||
$fees = $fees + $this->fees;
|
||||
if ( property_exists( $this, 'fees' ) ) {
|
||||
$fees = $fees + (array) $this->fees;
|
||||
}
|
||||
return $fees;
|
||||
}
|
||||
|
|
|
@ -142,10 +142,17 @@ abstract class WC_Legacy_Cart {
|
|||
$value = &$this->coupon_discount_tax_totals;
|
||||
break;
|
||||
case 'fees' :
|
||||
$this->fees = $this->get_fees();
|
||||
wc_deprecated_function( 'WC_Cart->fees', '3.2', sprintf( 'the fees API (%s)', 'WC_Cart::get_fees' ) );
|
||||
|
||||
// Grab fees from the new API.
|
||||
$new_fees = $this->fees_api()->get_fees();
|
||||
|
||||
// Add new fees to the legacy prop so it can be adjusted via legacy property.
|
||||
$this->fees = $new_fees;
|
||||
|
||||
// Return by reference.
|
||||
$value = &$this->fees;
|
||||
break;
|
||||
|
||||
// Deprecated args. TODO: Remove in 4.0.
|
||||
case 'tax' :
|
||||
wc_deprecated_argument( 'WC_Cart->tax', '2.3', 'Use WC_Tax directly' );
|
||||
|
@ -212,7 +219,8 @@ abstract class WC_Legacy_Cart {
|
|||
$this->set_coupon_discount_tax_totals( $value );
|
||||
break;
|
||||
case 'fees' :
|
||||
$this->fees_api->set_fees( $value );
|
||||
wc_deprecated_function( 'WC_Cart->fees', '3.2', sprintf( 'the fees API (%s)', 'WC_Cart::add_fee' ) );
|
||||
$this->fees = $value;
|
||||
break;
|
||||
default :
|
||||
$this->$name = $value;
|
||||
|
|
Loading…
Reference in New Issue