WooCommerce - Quantity (0.5 units) in products quantity (2 posts)

  1. ouverz
    Posted 2 years ago #

    Hi there,

    I'm building an e-commerce store which sells meat, poultry and the like -so units of products usually are in weight rather than units.
    I'm trying to figure out how I can configure the 'quantity' selector to have increments of 0.5 rather than the default (=1).
    Another idea I had was to eliminate the 'quantity' selector all together and have the weight of the products referenced by variables (weight - 0.5kg,1.0kg,1.5kg etc) - that selection would display the 'add to cart button'.
    I tried the code below but I had two issues:
    1. Although the initial and minimal values changed to 0.5 units, the increase/decrease is by 1 unit.
    2. The code affects only simple products and not variables as well, what would I need to do to have that affect variable products too?

    I saw a similar post but I didn't understand how they achieved this
    Best Regards and thanks in advance
    ===================================Code Below======================
    add_action( 'init', 'add_filter_to_overwrite_increment' );

    function add_filter_to_overwrite_increment() {
    add_filter( 'woocommerce_quantity_input_args', 'overwrite_woocommerce_quantity_input_args', 10, 2 );

    function overwrite_woocommerce_quantity_input_args( $args, $product ) {
    $args['input_value'] = 0.5; // Starting quantity value
    $args['max_value'] = 10; // Quantity can not go beyond this value
    $args['min_value'] = 0.5; // Quantity cannot go below this value
    $args['step'] = 0.5; // Value with which you want to increment or decrement
    return $args;


  2. dubzzdigital
    Posted 2 years ago #

    I am trying to achieve similar. We are using the plugin WP e-Commerce by GetShopped.org for a fabric commerce site where the customer needs to be able to choose any length of fabric (in metres or part there of).

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic