Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Coupon_Discount_Calculator {
- private $context = null;
- public function __construct() {
- add_filter( "adp_context_created", array( $this, 'save_context' ) );
- add_filter( 'wdp_amount_saved', array( $this, 'add_woocommerce_coupon_discounts_to_saved_amount' ), 10, 2 );
- }
- public function save_context( $context ) {
- if ( !isset( $this->context ) ) {
- $this->context = $context;
- }
- return $context;
- }
- public function add_woocommerce_coupon_discounts_to_saved_amount( $amount_saved, $cart_items ) {
- $includeTax = 'incl' === $this->context->getTaxDisplayCartMode();
- foreach ( WC()->cart->get_coupons() as $wcCoupon ) {
- $code = $wcCoupon->get_code();
- $adpData = $wcCoupon->get_meta( 'adp', true, 'edit' );
- if ( !isset( $adpData['parts'] ) ) {
- /** @var $coupon CouponCart */
- $woocommerce_coupon_discount = WC()->cart->get_coupon_discount_amount( $code, !$includeTax );
- $amount_saved += $woocommerce_coupon_discount;
- }
- }
- return $amount_saved;
- }
- }
- new Coupon_Discount_Calculator();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement