WC_Abstract_Order::get_temporary_coupon
Get a coupon object populated from order line item metadata, to be used when reapplying coupons if the original coupon no longer exists.
Method of the class: WC_Abstract_Order{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->get_temporary_coupon( $coupon_item ): WC_Coupon;
- $coupon_item(WC_Order_Item_Coupon) (required)
- The order item corresponding to the coupon to reapply.
Changelog
| Since 8.7.0 | Introduced. |
WC_Abstract_Order::get_temporary_coupon() WC Abstract Order::get temporary coupon code WC 10.6.2
private function get_temporary_coupon( WC_Order_Item_Coupon $coupon_item ): WC_Coupon {
$coupon_object = new WC_Coupon();
// Since WooCommerce 8.7 a succinct 'coupon_info' line item meta entry is created
// whenever a coupon is applied to an order. Previously a more verbose 'coupon_data' was created.
$coupon_info = $coupon_item->get_meta( 'coupon_info', true );
if ( $coupon_info ) {
$coupon_object->set_short_info( $coupon_info );
return $coupon_object;
}
$coupon_data = $coupon_item->get_meta( 'coupon_data', true );
if ( $coupon_data ) {
$coupon_object->set_props( (array) $coupon_data );
}
return $coupon_object;
}