Merge pull request #23663 from danielbitzer/add_get_coupons_method
Add WC_Abstract_Order::get_coupons()
This commit is contained in:
commit
b7facc0674
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue