Woocomemerce edit quantity when add to cart plugin and php code

<?php



add_action('woocommerce_add_to_cart', 'custome_add_to_cart');

function custome_add_to_cart() {
    global $woocommerce;


    remove_action('woocommerce_add_to_cart', __FUNCTION__);

    $product_id = isset($_POST["product_id"]) ? $_POST["product_id"] : $_POST["add-to-cart"];

    if ($unit_ = get_post_meta($product_id,"min_quantity",true)){

        $woocommerce->cart->add_to_cart((int) $product_id ,   ((int) $_POST["quantity"] * $unit_) - 1);

    }


}

Leave a Reply

Your email address will not be published. Required fields are marked *