• Resolved kimruddock

    (@kimruddock)


    Is it possible to grab the set quantity step value from the product object in order to display the required step amount to the user on the product page? I want to display this message next to the quantity field so the user knows what quantity step they must order in.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Kawsar Ahmed Rubel

    (@kawsarahmedr)

    Hi there,

    You can use the wcmmq_get_product_limits() function to retrieve product limit details. This function provides an array containing various values, such as the step, min_qty, max_qty, min_total, max_total and rule.

    Example:
    Retrieving Product Limits:
    $limits = wcmmq_get_product_limits( $product_id );

    Accessing Specific Data (e.g., step):

    if ( $limits && isset( $limits['step'] ) ) {
    $step = $limits['step'];
    }

    Once you have the step value, you can use it to display relevant notices or take other actions as needed.

    Code to Display Step Value After the Add to Cart Form:

    You can add the following code to your theme’s functions.php file or use a code insertion plugin like “Insert Codes

    /**
    * Display the quantity step message after the add to cart form.
    */
    function uniqueprefix_display_quantity_step_message() {
    global $product;

    if ( ! $product ) {
    return;
    }

    // Retrieve product limits, including the step value.
    $limits = function_exists( 'wcmmq_get_product_limits' ) ? wcmmq_get_product_limits( $product->get_id() ) : [];

    if ( isset( $limits['step'] ) && ! empty( $limits['step'] ) ) {
    $step_value = intval( $limits['step'] );

    // Display the message after the add to cart form.
    echo '<p class="quantity-step-message">';
    printf( /* translators: %d: step value */ esc_html__( 'Please order in multiples of %d.', 'your-text-domain' ), absint( $step_value ) );
    echo '</p>';
    }
    }
    add_action( 'woocommerce_after_add_to_cart_form', 'uniqueprefix_display_quantity_step_message' );

    Warning!

    The above PHP code may break your site. Please verify before using it.

    This code will display a message after the product’s quantity field and add-to-cart button, informing customers about the required step value for quantity.

    Let me know if you need further assistance!

    Thanks!
    Regards,
    Kawsar Ahmed

    Thread Starter kimruddock

    (@kimruddock)

    That’s incredibly helpful. Thank you so much for your detailed reply. Fantastic support response!

    Plugin Support Maruf Hossain

    (@marufbyteever)

    We’re happy to know that it works for your needs. Your feedback means a lot to us!

    As we assume your needs are fulfilled, we are going to close this support ticket. However, you can always reopen it if you require any further assistance.

    Thank you for using WC Min Max Quantities!

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.