I have set a Decimal quantity step for specific product categories in WooCommerce with a minimum order quantity of 2.5 for a particular category.
I would Like to add a minimum order quantity of 5 for a different category as well.
I am using the below code for step increment of 0.5 with MOQ of 2.5 for a category (tag ID- 174) but I don't know how can I add the MOQ of 5 in the code for a different category (tag ID-182)
<?php
// custom conditional function (check for product categories)
function enabled_decimal_quantities( $product ){
$targeted_terms = array(174); // Here define your product category terms (names, slugs ord Ids)
return has_term( $targeted_terms, 'product_cat', $product->get_id() );
}
// Defined quantity arguments
add_filter( 'woocommerce_quantity_input_args', 'custom_quantity_input_args', 9000, 2 );
function custom_quantity_input_args( $args, $product ) {
if( enabled_decimal_quantities( $product ) ) {
if( ! is_cart() ) {
$args['input_value'] = 2.5; // Starting value
}
$args['min_value'] = 2.5; // Minimum value
$args['step'] = 0.5; // Quantity steps
}
return $args;
}
add_filter( 'woocommerce_defer_transactional_emails', '__return_true' );
// For Ajax add to cart button (define the min value)
add_filter( 'woocommerce_loop_add_to_cart_args', 'custom_loop_add_to_cart_quantity_arg', 10, 2 );
function custom_loop_add_to_cart_quantity_arg( $args, $product ) {
if( enabled_decimal_quantities( $product ) ) {
$args['quantity'] = 1; // Min value
}
return $args;
}
// For product variations (define the min value)
add_filter( 'woocommerce_available_variation', 'filter_wc_available_variation_price_html', 10, 3);
function filter_wc_available_variation_price_html( $data, $product, $variation ) {
if( enabled_decimal_quantities( $product ) ) {
$data['min_qty'] = 1;
}
return $data;
}
// Enable decimal quantities for stock (in frontend and backend)
remove_filter('woocommerce_stock_amount', 'intval');
add_filter('woocommerce_stock_amount', 'floatval');
remove_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_add_to_cart', 15 );
add_filter( 'woocommerce_product_description_tab_title', 'bbloomer_rename_description_product_tab_label' );
function bbloomer_rename_description_product_tab_label() {
return 'Size Guide';
}
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );
add_filter('woocommerce_duplicate_product_capability', 'wc_duplicate_product_cap', 10, 1);
function wc_duplicate_product_cap( $cap ) {
$cap = 'edit_products';
return $cap;
}
/*************** MOQ ***************/