Support » Plugin: YITH WooCommerce Dynamic Pricing and Discounts » conflict with WooCommerce Smart Coupons and Save For Later For WooCommerce

  • Resolved Truong Nguyen

    (@quoctruong027)


    Hello,
    There is conflict with WooCommerce Smart Coupons plugin and Save For Later For WooCommerce plugin, the discount does not apply. Is there any way to solve it?
    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi @quoctruong027
    for premium support you have to open a support ticket on yithemes.com

    @quoctruong027 I have the same problem. Did you find the solution ?

    Thread Starter Truong Nguyen

    (@quoctruong027)

    @drascic You can try to add the code to the functions.php of your child theme:

    if ( class_exists( 'WC_SC_Auto_Apply_Coupon' ) ) {
     remove_action( 'wp_loaded', array( WC_SC_Auto_Apply_Coupon::get_instance(), 'auto_apply_coupons' ) );
     add_action( 'wp_loaded', 'yith_ywdpd_fix_wc_smart_coupons' );
    
     function yith_ywdpd_fix_wc_smart_coupons() {
    
      $cart = ( is_object( WC() ) && isset( WC()->cart ) ) ? WC()->cart : null;
      if ( ! empty( $cart->cart_contents ) ) {
          $auto_apply_coupon_ids = get_site_option( 'wc_sc_auto_apply_coupon_ids', array() );
          if ( ! empty( $auto_apply_coupon_ids ) && is_array( $auto_apply_coupon_ids ) ) {
        $valid_coupon_counter = 0;
        foreach ( $auto_apply_coupon_ids as $apply_coupon_id ) {
            // Process only five coupons.
            if ( apply_filters( 'wc_sc_max_auto_apply_coupons_limit', 5 ) === $valid_coupon_counter ) {
          break;
            }
            $coupon = new WC_Coupon( $apply_coupon_id );
            if ( $this->is_wc_gte_30() ) {
          $coupon_id = ( ! empty( $coupon ) && is_callable( array( $coupon, 'get_id' ) ) ) ? $coupon->get_id() : 0;
            } else {
          $coupon_id = ( ! empty( $coupon->id ) ) ? $coupon->id : 0;
            }
            // Check if it is a valid coupon object.
            if ( $apply_coupon_id === $coupon_id ) {
          if ( $this->is_wc_gte_30() ) {
              $coupon_code   = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_code' ) ) ) ? $coupon->get_code() : '';
              $discount_type = ( is_object( $coupon ) && is_callable( array( $coupon, 'get_discount_type' ) ) ) ? $coupon->get_discount_type() : '';
          } else {
              $coupon_code   = ( ! empty( $coupon->code ) ) ? $coupon->code : '';
              $discount_type = ( ! empty( $coupon->discount_type ) ) ? $coupon->discount_type : '';
          }
          if ( ! empty( $coupon_code ) && 'smart_coupon' !== $discount_type && $coupon->is_valid() ) {
              $cart_total = ( $this->is_wc_greater_than( '3.1.2' ) ) ? $cart->get_cart_contents_total() : $cart->cart_contents_total;
              // Check if cart still requires a coupon discount and does not have coupon already applied.
              if ( $cart_total > 0 && ! $cart->has_discount( $coupon_code ) ) {
            $cart->add_discount( $coupon_code );
              }
              $valid_coupon_counter++;
          }
            }
        }
          }
      }
     }
    }

    @quoctruong027

    Thank you. Let me try. Will let you know as soon as I try the code. Thank’s again for your time and effort. Really appreciate it.

    • This reply was modified 1 year, 6 months ago by drascic.
    • This reply was modified 1 year, 6 months ago by drascic.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘conflict with WooCommerce Smart Coupons and Save For Later For WooCommerce’ is closed to new replies.