Home / Admin / BOGO Coupons to refer to original subtotal
Duplicate Snippet

Embed Snippet on Your Site

BOGO Coupons to refer to original subtotal

When a BOGO coupon has a minimum spend (Usage Restriction) configured, applying the coupon can incorrectly fail with "The minimum spend for this coupon has not been met" — even when the original cart subtotal clearly exceeds the threshold.

Code Preview
php
<?php
add_filter( 'woocommerce_coupon_validate_minimum_amount', function ( $is_invalid, $coupon, $subtotal ) {
	if ( ! $is_invalid ) {
		return $is_invalid;
	}
	$bogo_deals = get_post_meta( $coupon->get_id(), '_acfw_bogo_deals', true );
	if ( empty( $bogo_deals ) ) {
		return $is_invalid;
	}
	$pre_bogo_subtotal = 0.0;
	foreach ( WC()->cart->get_cart_contents() as $item ) {
		$original_price     = (float) ( $item['data']->get_sale_price() ?: $item['data']->get_regular_price() );
		$pre_bogo_subtotal += $original_price * (int) $item['quantity'];
	}
	if ( $pre_bogo_subtotal <= 0 ) {
		return $is_invalid;
	}
	return $coupon->get_minimum_amount() > $pre_bogo_subtotal;
}, 20, 3 );

Comments

Add a Comment