• Resolved ceciestmonsurnom

    (@ceciestmonsurnom)


    Hello,
    I would like to set a minimum quantity on one of my products. It is a fabric. It should be sold from 50 cm, with the possibility for the customer to add quantity every 10 cm (50 ; 60 ; 70…). Is it possible with your plugin ?
    Best regards,

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Condless

    (@condless)

    Hi,
    In the product ‘Unit Price’ settings set 10 in ‘Quantity Step’.
    Copy the code from the plugin’s docs ‘How to set minimum quantity’ into your theme’s functions file, and update inside the code (instead of the other numbers):
    ’10’ => ’50’,
    which means all the products which have ‘Quantity Step’ of 10 will have minimum quantity of 50.

    Thread Starter ceciestmonsurnom

    (@ceciestmonsurnom)

    Hi,
    Thanks for your response.

    I specified in Unit Price “0,10” and added this code into my theme’s functions file :

    add_filter( 'upw_skip_args_validation', '__return_true' );
    add_filter( 'upw_product_min_value', 'upw_set_min_value' );
    add_filter( 'upw_variation_min_qty', 'upw_set_min_value' );
    add_filter( 'woocommerce_update_cart_validation', 'upw_apply_min_quantity', 10, 4 );
    
    function upw_set_min_value( $step ) {
    	$min_values = [
    		'0.10'	=> '0.50',
    		'0.10'	=> '0.50',
    	];
    	return isset( $min_values[ $step ] ) ? $min_values[ $step ] : $step;
    }
    
    function upw_apply_min_quantity( $passed, $cart_item_key, $values, $quantity ) {
    	$min_values = [
    		'0.10'	=> '0.50',
    		'0.10'	=> '0.50',
    	];
    	$step = $values['data']->get_meta( '_upw_step' );
    	if ( $step && isset( $min_values[ $step ] ) && $quantity < $min_values[ $step ] ) {
    		wc_add_notice( __( 'A minimum order amount', 'woocommerce' ) . ' (' . $values['data']->get_name() . '): ' . $min_values[ $step ], 'error' );
    		return false;
    	}
    	return $passed;
    }

    Unfortunately it does not work correctly, I’m sure I’m missing something ! Can you please help ?

    Best regards,

    Plugin Author Condless

    (@condless)

    Hi,
    If the Quantity Step is ‘0,10’ the code should contain exactly the same (and not ‘0.10’).

    Thread Starter ceciestmonsurnom

    (@ceciestmonsurnom)

    Hi,
    Nothing changed. Display price is not correct if I do not refresh the page, and from 0,7 next number is 0,799. See : https://netmove.fr/wordpress/produit/popeline-de-coton/

    Thanks,

    Plugin Author Condless

    (@condless)

    Hi,
    Please redownload the plugin, then change the Quantity Step (both in option and in code) to 0.1 instead of 0.10.

    Thread Starter ceciestmonsurnom

    (@ceciestmonsurnom)

    Hi,
    Thanks, all done ! Price is now correct, but I still have the same problem from 0,7 (next number is 7,99).
    Regards,

    Plugin Author Condless

    (@condless)

    Hi,
    The quantity buttons of your theme doesn’t fully support decimal quantity step.
    You can replace them using this plugin.
    Then redownload the Unit Price plugin and add this CSS (to hide the quantity buttons in mini cart):

    .widget_shopping_cart_content .qib-button {
       display: none !important;
    }
    Thread Starter ceciestmonsurnom

    (@ceciestmonsurnom)

    Hi,
    Thanks it’s working !

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to set a minimum quantity’ is closed to new replies.