WC_Cart::set_quantity PHP 메소드

set_quantity() 공개 메소드

Set the quantity for an item in the cart.
public set_quantity ( string $cart_item_key, integer $quantity = 1, boolean $refresh_totals = true ) : boolean
$cart_item_key string contains the id of the cart item
$quantity integer contains the quantity of the item
$refresh_totals boolean whether or not to calculate totals after setting the new qty
리턴 boolean
    public function set_quantity($cart_item_key, $quantity = 1, $refresh_totals = true)
    {
        if (0 == $quantity || $quantity < 0) {
            do_action('woocommerce_before_cart_item_quantity_zero', $cart_item_key);
            unset($this->cart_contents[$cart_item_key]);
        } else {
            $old_quantity = $this->cart_contents[$cart_item_key]['quantity'];
            $this->cart_contents[$cart_item_key]['quantity'] = $quantity;
            do_action('woocommerce_after_cart_item_quantity_update', $cart_item_key, $quantity, $old_quantity);
        }
        if ($refresh_totals) {
            $this->calculate_totals();
        }
        return true;
    }
WC_Cart