Automattic\WooCommerce\StoreApi\Utilities
CartController::filter_request_data()
Filter data for add to cart requests.
Метод класса: CartController{}
Возвращает
Массив
. Updated request array.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->filter_request_data( $request );
- $request(массив) (обязательный)
- Add to cart request params.
Код CartController::filter_request_data() CartController::filter request data WC 9.8.1
protected function filter_request_data( $request ) { $product_id = $request['id']; $variation_id = 0; $product = wc_get_product( $product_id ); if ( $product->is_type( ProductType::VARIATION ) ) { $product_id = $product->get_parent_id(); $variation_id = $product->get_id(); } /** * Filter cart item data for add to cart requests. * * @since 2.5.0 * * @internal Matches filter name in WooCommerce core. * * @param array $cart_item_data Array of other cart item data. * @param integer $product_id ID of the product added to the cart. * @param integer $variation_id Variation ID of the product added to the cart. * @param integer $quantity Quantity of the item added to the cart. * @return array */ $request['cart_item_data'] = (array) apply_filters( 'woocommerce_add_cart_item_data', $request['cart_item_data'], $product_id, $variation_id, $request['quantity'] ); if ( $product->is_sold_individually() ) { /** * Filter sold individually quantity for add to cart requests. * * @since 2.5.0 * * @internal Matches filter name in WooCommerce core. * * @param integer $sold_individually_quantity Defaults to 1. * @param integer $quantity Quantity of the item added to the cart. * @param integer $product_id ID of the product added to the cart. * @param integer $variation_id Variation ID of the product added to the cart. * @param array $cart_item_data Array of other cart item data. * @return integer */ $request['quantity'] = apply_filters( 'woocommerce_add_to_cart_sold_individually_quantity', 1, $request['quantity'], $product_id, $variation_id, $request['cart_item_data'] ); } return $request; }