Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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++;
          }
            }
        }
          }
      }
     }
    }
    Thread Starter Truong Nguyen

    (@quoctruong027)

    I filled in that form three days ago, but I haven’t received any response yet

    Thread Starter Truong Nguyen

    (@quoctruong027)

    I used “free gift” and “Percentage off order subtotal” for my website.

Viewing 3 replies - 1 through 3 (of 3 total)