Skip to content

Commit

Permalink
add: new filters to validate the minimum and maximum amount
Browse files Browse the repository at this point in the history
  • Loading branch information
mralaminahamed committed Jan 13, 2025
1 parent 2624bee commit 974c0d6
Showing 1 changed file with 57 additions and 11 deletions.
68 changes: 57 additions & 11 deletions includes/Order/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,63 @@ public function ensure_coupon_is_valid( bool $valid, WC_Coupon $coupon, WC_Disco
throw new Exception( esc_html__( 'This coupon is invalid for multiple vendors.', 'dokan-lite' ) );
}

/**
* Filter the validity of a coupon.
*
* @since DOKAN_SINCE
*
* @param boolean $valid The validity of the coupon.
* @param WC_Coupon $coupon The coupon object.
* @param array $available_vendors List of available vendors.
* @param array $available_products List of available products.
* @param WC_Discounts $discounts The discount object, which contains the order details.
*/
/**
* Filter to customize minimum amount validation for vendor coupons.
*
* Allows modifying whether a coupon should be valid based on the minimum order amount requirement.
*
* @since DOKAN_SINCE
*
* @param bool $is_valid True if the minimum amount requirement is met
* @param WC_Coupon $coupon The coupon object being validated
* @param float $subtotal The current order subtotal
* @param WC_Discounts $discounts The WC_Discounts object containing cart/order details
*/
if ( ! apply_filters( 'dokan_coupon_validate_minimum_amount', true, $coupon, $discounts ) ) {
throw new Exception(
sprintf(
/* translators: %s: minimum spend amount for coupon */
esc_html__( 'The minimum spend for this coupon is %s', 'dokan' ),

Check failure on line 459 in includes/Order/Hooks.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Mismatched text domain. Expected 'dokan-lite' but got 'dokan'.
esc_html( wc_price( $coupon->get_minimum_amount() ) )
),
108
);
}

/**
* Filter to customize maximum amount validation for vendor coupons.
*
* Allows modifying whether a coupon should be valid based on the maximum order amount requirement.
*
* @since DOKAN_SINCE
*
* @param bool $is_valid True if the maximum amount requirement is met
* @param WC_Coupon $coupon The coupon object being validated
* @param float $subtotal The current order subtotal
* @param WC_Discounts $discounts The WC_Discounts object containing cart/order details
*/
if ( ! apply_filters( 'dokan_coupon_validate_maximum_amount', true, $coupon, $discounts ) ) {
throw new Exception(
sprintf(
/* translators: %s: maximum spend amount for coupon */
esc_html__( 'The maximum spend for this coupon is %s', 'dokan' ),

Check failure on line 482 in includes/Order/Hooks.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Mismatched text domain. Expected 'dokan-lite' but got 'dokan'.
esc_html( wc_price( $coupon->get_maximum_amount() ) )
),
108
);
}

/**
* Filter the validity of a coupon.
*
* @since DOKAN_SINCE
*
* @param boolean $valid The validity of the coupon.
* @param \WC_Coupon $coupon The coupon object.
* @param array $available_vendors List of available vendors.
* @param array $available_products List of available products.
* @param \WC_Discounts $discounts The discount object, which contains the order details.
*/
return apply_filters( 'dokan_coupon_is_valid', $valid, $coupon, $available_vendors, $available_products, $discounts );
}

Expand Down

0 comments on commit 974c0d6

Please sign in to comment.