abandoned-cart-hooks.php
3 years ago
cartbounty.php
3 years ago
smart-coupons.php
5 months ago
wati.php
2 years ago
smart-coupons.php
26 lines
| 1 | <?php |
| 2 | //Support for smart coupon plugin - restricted by payment method options |
| 3 | function smartCouponPaymentRestriction($couponCode){ |
| 4 | $coupon = new WC_Coupon($couponCode); |
| 5 | |
| 6 | // Get payment methods meta |
| 7 | $methodsMeta = get_post_meta( $coupon->get_id(), '_wt_sc_payment_methods', true ); |
| 8 | |
| 9 | // Normalize to array (handle both array and comma-separated string cases) |
| 10 | // - If it's already an array, use it as-is. |
| 11 | // - If it's a non-empty comma-separated string, split by commas and remove extra spaces or empty values. |
| 12 | // - Otherwise, use an empty array. |
| 13 | $methods = is_array($methodsMeta) |
| 14 | ? $methodsMeta |
| 15 | : (is_string($methodsMeta) && $methodsMeta !== '' |
| 16 | ? array_filter(preg_split('/\s*,\s*/', $methodsMeta)) |
| 17 | : array()); |
| 18 | |
| 19 | // Normalize case (lowercase all methods) |
| 20 | $methods = array_map( 'strtolower', $methods ); |
| 21 | |
| 22 | // Check if Razorpay is allowed |
| 23 | if ( in_array( 'razorpay', $methods, true ) && function_exists( 'WC' ) && WC()->session ) { |
| 24 | WC()->session->set( 'chosen_payment_method', 'razorpay' ); |
| 25 | } |
| 26 | } |