WC_Cart_Totals::get_coupons_from_cart
Return array of coupon objects from the cart. Normalises data into the same format for use by this class.
Метод класса: WC_Cart_Totals{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_coupons_from_cart();
Список изменений
| С версии 3.2.0 | Введена. |
Код WC_Cart_Totals::get_coupons_from_cart() WC Cart Totals::get coupons from cart WC 11.2.2
protected function get_coupons_from_cart() {
$this->coupons = $this->cart->get_coupons();
$this->coupon_application_positions = array();
// The position tie-break only applies once two coupons can tie, and this setting is not autoloaded,
// so skip the option read for coupon-free and single-coupon carts.
$sequential_discounts = count( $this->coupons ) > 1 && 'yes' === get_option( 'woocommerce_calc_discounts_sequentially' );
$position = 0;
foreach ( $this->coupons as $coupon ) {
if ( $sequential_discounts ) {
$this->coupon_application_positions[ spl_object_id( $coupon ) ] = $position++;
}
switch ( $coupon->get_discount_type() ) {
case 'fixed_product':
$coupon->sort = 1;
break;
case 'percent':
$coupon->sort = 2;
break;
case 'fixed_cart':
$coupon->sort = 3;
break;
default:
$coupon->sort = 0;
break;
}
// Allow plugins to override the default order.
$coupon->sort = apply_filters( 'woocommerce_coupon_sort', $coupon->sort, $coupon );
}
uasort( $this->coupons, array( $this, 'sort_coupons_callback' ) );
}