• Resolved kamilen12

    (@kamilen12)


    Hello, I have a problem. I’m trying to set this:

    
    // Add min value to the quantity field (default = 1)
    add_filter('woocommerce_quantity_input_min', 'min_decimal');
    function min_decimal($val) {
        return 0.1;
    }
     
    // Add step value to the quantity field (default = 1)
    add_filter('woocommerce_quantity_input_step', 'nsk_allow_decimal');
    function nsk_allow_decimal($val) {
        return 0.01;
    }
     
    // Removes the WooCommerce filter, that is validating the quantity to be an int
    remove_filter('woocommerce_stock_amount', 'intval');
     
    // Add a filter, that validates the quantity to be a float
    add_filter('woocommerce_stock_amount', 'floatval');
     
    // Add unit price fix when showing the unit price on processed orders
    add_filter('woocommerce_order_amount_item_total', 'unit_price_fix', 10, 5);
    function unit_price_fix($price, $order, $item, $inc_tax = false, $round = true) {
        $qty = (!empty($item['qty']) && $item['qty'] != 0) ? $item['qty'] : 1;
        if($inc_tax) {
            $price = ($item['line_total'] + $item['line_tax']) / $qty;
        } else {
            $price = $item['line_total'] / $qty;
        }
        $price = $round ? round( $price, 2 ) : $price;
        return $price;
    }
    

    (the snippet which lets entering, as you see, decimal quantities while ordering a products.)
    And it’s working correctly, but the thing I wanted (and I still want) to do, is to set this snippets only for variable (variation) products.
    I tried to use this:

    
    // Add min value to the quantity field (default = 1)
    add_filter('woocommerce_quantity_input_min', 'min_decimal', 10, 2 );
    function min_decimal($val, $product) {
        if ( $product->is_type( 'variable' ) ) {
            return 0.1;
        }
        return $val;
    }
     
    // Add step value to the quantity field (default = 1)
    add_filter('woocommerce_quantity_input_step', 'nsk_allow_decimal', 10, 2 );
    function nsk_allow_decimal($val, $product) {
        if ( $product->is_type( 'variable' ) ) {
            return 0.01;
        }
        return $val;
    }
    

    (the first two snippets now have if function)
    And it’s also working but not in 100%. It’s working on site, for a customer. But problems begins when I’m getting into order on the admin site. Some buttons just don’t work. If I want to correct an order or send a invoice for a customer I’m not able. The button works only like there wasn’t any href. So I’m hovering on it, it changes color a bit, I click on it and this border around button appears, but this button doesn’t make any action.

    Thank you in advance for the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Ross V. a11n

    (@rossviviano)

    Automattic Happiness Engineer

    Hi there,

    This is a fairly complex development topic, so I’m going to leave it open for a bit to see if anyone is able to jump in to help you out.

    I can also recommend the following places for more development-oriented questions:

    WooCommerce Slack Community: https://woocommerce.com/community-slack/
    Advanced WooCommerce group on Facebook: https://www.facebook.com/groups/advanced.woocommerce/

    Ross

    Thread Starter kamilen12

    (@kamilen12)

    Hello,
    I think I have repaired it. I’ve came back to my previous code, which let customers to order decimal in every product, but I’ve add some code:

    
    add_filter( 'woocommerce_quantity_input_args', 'bloomer_woocommerce_quantity_changes', 10, 2 );
       
    function bloomer_woocommerce_quantity_changes( $args, $product ) {
       
    	if( $product->is_type( 'simple' ) ){  
          $args['step'] = 1; // Increment/decrement by this value (default = 1)
    	}   
       return $args;
       
    }
    

    So now it’s working as it should (at least it seems so).
    I’m writing it for the others. Maybe someone will have similar problem.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WooCommerce: Buttons don’t work correctly’ is closed to new replies.