I’ve found a fix for this. The follow code is properly styled, fully compatible and works correctly, i.e. it adds the correct minimum quantity to the cart for simple products and links variable product buttons to the respective product page:
add_filter( 'woocommerce_loop_add_to_cart_link','_wcmmax_add2cart' );
function _wcmmax_add2cart( $link ) {
global $product;
$product_id = $product->get_id();
$product_sku = $product->get_sku();
$product_type = $product->get_type();
$qtylink = '';
$mmaxEnable = get_post_meta( $product_id, '_wc_mmax_prd_opt_enable', true );
$minQty = get_post_meta( $product_id, '_wc_mmax_min', true );
if ( $product_type != 'simple' || $mmaxEnable != 1 ){
return $link;
}
$qtylink = '&quantity='.$minQty;
$ajax_cart_en = 'yes' === get_option( 'woocommerce_enable_ajax_add_to_cart' );
if ( $ajax_cart_en && $mmaxEnable == 0 ) {
$ajax_class = 'ajax_add_to_cart';
}
$link = sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" data-quantity="%s" class="button %s product_type_%s %s">%s</a>',
esc_url( $product->add_to_cart_url().$qtylink ),
esc_attr( $product_id ),
esc_attr( $product->get_sku() ),
esc_attr( isset( $minQty ) ? $minQty : 1 ),
$product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
esc_attr( $product->product_type ),
esc_attr( $ajax_class ),
esc_html( $product->add_to_cart_text() )
);
return $link;
}
@wpashokg please udpate the plugin.