Repository Forums Support WooCommerce Extended Coupon Features PRO Auto coupons overriding my ‘woocommerce_coupon_is_valid_for_product’ filter?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #17889
    Leland Zaremba
    Participant

    Hello,

    I currently have a filter in place to disqualify a specific list of coupons for all subscriptions products. I am using this: woocommerce_coupon_is_valid_for_product’, ‘my_function_with_coupons’, 10, 4 );. It works great except it appears that all of the auto-add coupons override this filter and allow the coupon to be added either way. This is a big problem. What can I do to stop this so we can use the auto-add functionality?

    #17891
    Soft79
    Keymaster

    What is the content of your filter? Can you paste it here or on pastebin, please? Also, in what action do you apply the filter?

    Our plugin needs woocommerce_coupon_is_valid_for_product but will only override the result in case it needs to enable/disable validity, so it depends on the coupon settings.

    #17895
    Leland Zaremba
    Participant
    add_filter( 'woocommerce_coupon_is_valid_for_product', 'wc_apfs_disable_coupons', 10, 4 );
    function wc_apfs_disable_coupons( $is_valid,  $product,  $instance,  $values ) {
    
      if ( in_array( $instance->get_code(), array( 'retail50', 'fourth', 'FOURTH','regimentier10', 'regimentier20', 'regimentier30' ) ) ) {
        if ( ! empty( $values[ 'wcsatt_data'][ 'active_subscription_scheme' ] ) ) {
          $is_valid = false;
        }
      }
    
      return $is_valid;
    }

    This code is designed to disable coupons for products that have subscription options. This needs to override any other coupon rule. These subscription products are created using the official “woocommerce all products for subscriptions” WC plugin.

    #17896
    Soft79
    Keymaster

    Try changing the filter priority to 900

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.