WC_Discounts::get_items_to_apply_coupon()
Get items which the coupon should be applied to.
Метод класса: WC_Discounts{}
Хуки из метода
Возвращает
Массив
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_items_to_apply_coupon( $coupon );
- $coupon(объект) (обязательный)
- Coupon object.
Список изменений
С версии 3.2.0 | Введена. |
Код WC_Discounts::get_items_to_apply_coupon() WC Discounts::get items to apply coupon WC 9.8.5
protected function get_items_to_apply_coupon( $coupon ) { $items_to_apply = array(); foreach ( $this->get_items_to_validate() as $item ) { $item_to_apply = clone $item; // Clone the item so changes to this item do not affect the originals. if ( 0 === $this->get_discounted_price_in_cents( $item_to_apply ) || 0 >= $item_to_apply->quantity ) { continue; } if ( ! $coupon->is_valid_for_product( $item_to_apply->product, $item_to_apply->object ) && ! $coupon->is_valid_for_cart() ) { continue; } $items_to_apply[] = $item_to_apply; } /** * Filters the items that a coupon should be applied to. * * This filter allows you to modify the items that a coupon will be applied to before the discount calculations take place. * * @since 8.8.0 * @param array $items_to_apply The items that the coupon will be applied to. * @param WC_Coupon $coupon The coupon object. * @param WC_Discounts $this The discounts instance. * * @return array The modified list of items that the coupon should be applied to. */ return apply_filters( 'woocommerce_coupon_get_items_to_apply', $items_to_apply, $coupon, $this ); }