Merge pull request #23663 from danielbitzer/add_get_coupons_method

Add WC_Abstract_Order::get_coupons()
This commit is contained in:
Gerhard Potgieter 2019-05-14 11:35:21 +02:00 committed by GitHub
commit b7facc0674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -730,6 +730,16 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
return apply_filters( 'woocommerce_order_get_items', $items, $this, $types );
}
/**
* Return an array of coupons within this order.
*
* @since 3.7.0
* @return WC_Order_Item_Coupon[]
*/
public function get_coupons() {
return $this->get_items( 'coupon' );
}
/**
* Return an array of fees within this order.
*

View File

@ -312,6 +312,24 @@ class WC_Tests_CRUD_Orders extends WC_Unit_Test_Case {
$this->assertCount( 2, $object->get_items( array( 'line_item', 'fee' ) ) );
}
/**
* Test: get_coupons
*/
public function test_get_coupons() {
$object = new WC_Order();
$item = new WC_Order_Item_Coupon();
$item->set_props(
array(
'code' => '12345',
'discount' => 10,
'discount_tax' => 5,
)
);
$object->add_item( $item );
$object->save();
$this->assertCount( 1, $object->get_coupons() );
}
/**
* Test: get_fees
*/