WooCommerce购物车中特定类别的最大产品数量

时间:2016-04-09 18:09:51

标签: php wordpress woocommerce limit product

如何设置同类别购物车中的商品数量限制?
这也可以用相同价格的产品来完成吗?

非常感谢你。

function wpbo_minimum_item_quantity_validation( $passed, $product_id, $quantity, $variation_id, $variations ) {
    // Make $woocommerce accessible
    global $woocommerce;

    // Set a minimum item quantity
    $minimum = 10; 

    // Check if the quantity is smaller than our minimum value
    if ( $quantity < $minimum ) {

        // Get the product title for the error statement
        $product = get_product( $product_id );
        $product_title = $product->post->post_title;

        // Add the error
        $woocommerce->add_error( sprintf( "You must add a minimum of %s %s's to your cart to proceed." , $minimum, $product_title ) );

    // If the quantity is 10 or above return true
    } else {
        return true;
    }
}

0 个答案:

没有答案