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 / Coupons.php

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

74 lines 2.0 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 Coupons extends AbstractAddon {
7
8 public function getName() {
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 ), 10, 3 );
20
21 add_action( 'tiered_pricing_table/cart/need_price_recalculation/item', array(
22 $this,
23 'checkAppliedCoupons',
24 ), 10, 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 if ( get_post_meta( $coupon->get_id(), '_disable_tiered_pricing', true ) === 'yes' ) {
43 return false;
44 }
45 }
46
47 return $recalculate;
48 }
49
50 public function saveTieredPricingOption( $couponId ) {
51 update_post_meta( $couponId, '_disable_tiered_pricing',
52 isset( $_REQUEST['_disable_tiered_pricing'] ) ? 'yes' : 'no' );
53 }
54
55 public function addTieredPricingOption( $couponId, $coupon ) {
56
57 woocommerce_wp_checkbox( array(
58 'id' => '_disable_tiered_pricing',
59 'label' => __( 'Disable tiered pricing when the coupon is applied', 'woocommerce' ),
60 'description' => __( 'Check this option to don\'t apply tiered pricing in the cart when users have applied this coupon.',
61 'tier-pricing-table' ),
62 'value' => get_post_meta( $couponId, '_disable_tiered_pricing', true ),
63 ) );
64 }
65
66 public function getDescription() {
67 return __( 'Allows you to manage which coupons will allow tiered pricing and which ones will not.', 'tier-pricing-table' );
68 }
69
70 public function getSlug() {
71 return 'coupons';
72 }
73 }
74