Deprecate WC_Abstract_Order::get_used_coupons in favor of WC_Abstract_Order::get_used_coupon_codes, this reflects the actual data being returned better.

This commit is contained in:
Gerhard 2019-05-13 14:40:54 +02:00
parent 3755b23db5
commit 31acfbcb4a
3 changed files with 17 additions and 5 deletions

View File

@ -773,9 +773,21 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
/**
* Get coupon codes only.
*
* @deprecated 3.7.0 - Replaced with better named method to reflect the actual data being returned.
* @return array
*/
public function get_used_coupons() {
wc_deprecated_function( 'get_used_coupons', '3.7', 'WC_Abstract_Order::get_used_coupon_codes' );
return $this->get_used_coupon_codes();
}
/**
* Get used coupon codes only.
*
* @since 3.7.0
* @return array
*/
public function get_used_coupon_codes() {
$coupon_codes = array();
$coupons = $this->get_items( 'coupon' );

View File

@ -854,8 +854,8 @@ function wc_update_coupon_usage_counts( $order_id ) {
return;
}
if ( count( $order->get_used_coupons() ) > 0 ) {
foreach ( $order->get_used_coupons() as $code ) {
if ( count( $order->get_used_coupon_codes() ) > 0 ) {
foreach ( $order->get_used_coupon_codes() as $code ) {
if ( ! $code ) {
continue;
}

View File

@ -452,9 +452,9 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
}
/**
* Test: get_used_coupons
* Test: get_used_coupon_codes
*/
public function test_get_used_coupons() {
public function test_get_used_coupon_codes() {
$object = new WC_Order();
$item = new WC_Order_Item_Coupon();
$item->set_props(
@ -466,7 +466,7 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
);
$object->add_item( $item );
$object->save();
$this->assertCount( 1, $object->get_used_coupons() );
$this->assertCount( 1, $object->get_used_coupon_codes() );
}
/**