PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.1.0
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / Coupons / CouponsAddon.php

CouponsAddon.php in Tiered Pricing Table for WooCommerce 6.1.0, at src/Addons/Coupons/CouponsAddon.php

84 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\Coupons;
2
3 use TierPricingTable\Addons\AbstractAddon;
4 use WC_Cart;
5
6 class CouponsAddon extends AbstractAddon {
7
8 public function getName(): string {
9 return __( 'Coupons management', 'tier-pricing-table' );
10 }
11
12 public function run() {
13 add_action( 'woocommerce_coupon_options', array( $this, 'addTieredPricingOption' ), 10, 2 );
14 add_action( 'woocommerce_coupon_options_save', array( $this, 'saveTieredPricingOption' ), 10, 2 );
15
16 add_action( 'tiered_pricing_table/cart/need_price_recalculation', array(
17 $this,
18 'checkAppliedCoupons',
19 ), 999, 3 );
20
21 add_action( 'tiered_pricing_table/cart/need_price_recalculation/item', array(
22 $this,
23 'checkAppliedCoupons',
24 ), 999, 3 );
25 }
26
27 public function checkAppliedCoupons( $recalculate, $item, $cart = null ) {
28
29 $cart = $cart instanceof WC_Cart ? $cart : wc()->cart;
30
31 if ( ! $cart ) {
32 return $recalculate;
33 }
34
35 $coupons = $cart->get_coupons();
36
37 if ( empty( $coupons ) ) {
38 return $recalculate;
39 }
40
41 foreach ( $coupons as $coupon ) {
42
43 if ( ! $coupon instanceof \WC_Coupon ) {
44 continue;
45 }
46
47 if ( ! $coupon->is_valid_for_product( $item['data'] ) ) {
48 continue;
49 }
50
51 if ( get_post_meta( $coupon->get_id(), '_disable_tiered_pricing', true ) === 'yes' ) {
52 return false;
53 }
54 }
55
56 return $recalculate;
57 }
58
59 public function saveTieredPricingOption( $couponId ) {
60 update_post_meta( $couponId, '_disable_tiered_pricing',
61 isset( $_REQUEST['_disable_tiered_pricing'] ) ? 'yes' : 'no' );
62 }
63
64 public function addTieredPricingOption( $couponId, $coupon ) {
65
66 woocommerce_wp_checkbox( array(
67 'id' => '_disable_tiered_pricing',
68 'label' => __( 'Disable tiered pricing when the coupon is applied', 'woocommerce' ),
69 'description' => __( 'Check this option to don\'t apply tiered pricing in the cart when users have applied this coupon.',
70 'tier-pricing-table' ),
71 'value' => get_post_meta( $couponId, '_disable_tiered_pricing', true ),
72 ) );
73 }
74
75 public function getDescription(): string {
76 return __( 'It allows you to manage which coupons will allow tiered pricing and which will not.',
77 'tier-pricing-table' );
78 }
79
80 public function getSlug(): string {
81 return 'coupons';
82 }
83 }
84