false, 'code' => 'MB_COUPON_NOT_FOUND', ); } // Full WC_Coupon path (runtime). Lightweight stubs used in unit fixtures skip WP checks. $has_id = is_callable( array( $coupon, 'get_id' ) ); if ( $has_id ) { $id = (int) $coupon->get_id(); if ( $id <= 0 ) { return array( 'valid' => false, 'code' => 'MB_COUPON_NOT_FOUND', ); } if ( function_exists( 'get_post_status' ) && 'publish' !== get_post_status( $id ) ) { return array( 'valid' => false, 'code' => 'MB_COUPON_INACTIVE', ); } } if ( is_callable( array( $coupon, 'get_date_expires' ) ) ) { $exp = $coupon->get_date_expires(); if ( $exp && is_object( $exp ) && method_exists( $exp, 'getTimestamp' ) && $exp->getTimestamp() < time() ) { return array( 'valid' => false, 'code' => 'MB_COUPON_EXPIRED', ); } } if ( $line_subtotal instanceof MoneyAmount && is_callable( array( $coupon, 'get_minimum_amount' ) ) && is_callable( array( $coupon, 'get_maximum_amount' ) ) ) { $sub_s = $line_subtotal->to_decimal_string(); $min_s = trim( (string) $coupon->get_minimum_amount() ); $max_s = trim( (string) $coupon->get_maximum_amount() ); if ( '' !== $min_s && is_numeric( $min_s ) && function_exists( 'bccomp' ) ) { if ( bccomp( $min_s, '0', 6 ) > 0 && bccomp( $sub_s, $min_s, 6 ) < 0 ) { return array( 'valid' => false, 'code' => 'MB_COUPON_MIN_SPEND', ); } } if ( '' !== $max_s && is_numeric( $max_s ) && function_exists( 'bccomp' ) ) { if ( bccomp( $max_s, '0', 6 ) > 0 && bccomp( $sub_s, $max_s, 6 ) > 0 ) { return array( 'valid' => false, 'code' => 'MB_COUPON_MAX_SPEND', ); } } } return array( 'valid' => true, 'code' => null, ); } }