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