Okay
  Public Ticket #2934633
Display required multiple on single product page
Closed

Comments

  •  6
    christian paton started the conversation

    Hi there, I'm trying to display a message beside the quantity input showing the required multiple for a given product. Within "/woocommerce/single-product/add-to-cart" I have tried "$product->get_min_purchase_quantity()" and "apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product )" but this only gives me the non B2B amount, which is puzzling as it spits out the correct number for input field itself, so I can only assume you are filtering somehow that I can't figure out. I have also checked "get_post_meta( $product->id )" but cannot find the infromation there either.

    thanks in advance, chris

  •  2,218
    WebWizards replied

    Hi Chris,

    I looked a bit into this, it seems the following will work:

        $defaults = array(
            'input_id'     => uniqid( 'quantity_' ),
            'input_name'   => 'quantity',
            'input_value'  => '1',
            'classes'      => apply_filters( 'woocommerce_quantity_input_classes', array( 'input-text', 'qty', 'text' ), $product ),
            'max_value'    => apply_filters( 'woocommerce_quantity_input_max', -1, $product ),
            'min_value'    => apply_filters( 'woocommerce_quantity_input_min', 0, $product ),
            'step'         => apply_filters( 'woocommerce_quantity_input_step', 1, $product ),
            'pattern'      => apply_filters( 'woocommerce_quantity_input_pattern', has_filter( 'woocommerce_stock_amount', 'intval' ) ? '[0-9]*' : '' ),
            'inputmode'    => apply_filters( 'woocommerce_quantity_input_inputmode', has_filter( 'woocommerce_stock_amount', 'intval' ) ? 'numeric' : '' ),
            'product_name' => $product ? $product->get_title() : '',
            'placeholder'  => apply_filters( 'woocommerce_quantity_input_placeholder', '', $product ),
        );
        $args = apply_filters( 'woocommerce_quantity_input_args', wp_parse_args( array(), $defaults ), $product );
        echo $args['step']; // display the step 
        echo $args['min_value']; // display the min value
    

    Our plugin filters the 'woocommerce_quantity_input_args' hook. So you were quite close, but just a bit too early, you were getting the value before our plugin had a chance to filter it.


    Let me know if I can help with anything, or if you have any questions,

    Kind regards,

    Stefan

  •  6
    christian paton replied

    Ah perfect, that works for me, thanks again.

    Actually having a problem with the registration sjortcode not working, am I better to start another ticket or can I ask here?

  •  2,218
    WebWizards replied

    Glad that worked.

    Regarding the registration issue, feel free to ask here, let me know.

  •  6
    christian paton replied

    Cool, ta. OK so trying put the registration on a separate page and followed your guide but for some reason it's not executing this code. Bellow your shortcode is a ninja form that I was using befofre that is also generated from a shortcode from the same editor.

    https://staging8.esmie.co.uk/stockists-register/

  •  2,218
    WebWizards replied

    I checked, the issue is that the registration feature was disabled in B2BKing -> Settings -> Other -> Components:

    8009255915.png

    I re-enabled it now and it seems to be working at https://staging8.esmie.co.uk/stockists-register/

  •  6
    christian paton replied

    Ah yes, sorry I had forgotten that feature even existed, I must have toggled it back at the start when I was investigating the options. Anyway, perfect, thanks again.

    chris