• Resolved jinsley8

    (@jinsley8)


    Hi,

    Is there any way to disable partial payments only for one specific category?

    I have it already setup so this category can only be in the cart by itself.

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Subrata Mal

    (@subratamal)

    @jinsley8 You can enable disable wallet partial payment using filter woo_wallet_disable_partial_payment.

    Thread Starter jinsley8

    (@jinsley8)

    Okay thank you!

    @jinsley8 hi, did you achieve this?

    Thread Starter jinsley8

    (@jinsley8)

    @roberto22 no I did something else but to disable completely this is the full filter:

    add_filter('woo_wallet_disable_partial_payment', '__return_true');

    So to diable if a specific category is in the cart you could try this to check if a category is in the cart and return true if it is (change the ‘change-category-name’ to the category name):

    function disable_partial_payment_for_category() {
    
      // Set $cat_in_cart to false
      $cat_in_cart = false;
    
      // Loop through all products in the Cart
      foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    
        // If Cart has category "change-category-name", set $cat_in_cart to true
        if ( has_term( 'change-category-name', 'product_cat', $cart_item['product_id'] ) ) {
          $cat_in_cart = true;
          break;
        }
      }
    
      // set to true if "change-category-name" is in the Cart
      if ( $cat_in_cart ) {
        return true;
      }
    }
    add_filter( 'woocommerce_available_payment_gateways', 'disable_partial_payment_for_category' );

    @jinsley8 thanks, I’m gonna try the code!

    I was trying to use this snippet but didn’t work.

    add_filter( 'woocommerce_available_payment_gateways', 'bbloomer_unset_gateway_by_category' );
      
    function bbloomer_unset_gateway_by_category( $available_gateways ) {
        if ( is_admin() ) return $available_gateways;
        if ( ! is_checkout() ) return $available_gateways;
        $unset = false;
        $category_ids = array( 8, 37 );
        foreach ( WC()->cart->get_cart_contents() as $key => $values ) {
            $terms = get_the_terms( $values['product_id'], 'product_cat' );    
            foreach ( $terms as $term ) {        
                if ( in_array( $term->term_id, $category_ids ) ) {
                    $unset = true;
                    break;
                }
            }
        }
        if ( $unset == true ) unset( $available_gateways['wallet'] );
        return $available_gateways;
    }
    
    They also gave me another snippet but still didn’t work. You can check here is you want: https://www.ads-software.com/support/topic/remove-pay-with-wallet-for-a-specific-category/

    In case you make work, please let me know. Thanks!

    @jinsley8 Hi man, sorry to bother you again.

    I tried your code but it doesnt work for me. Is it working for you?

    `function disable_partial_payment_for_category() {

    // Set $cat_in_cart to false
    $cat_in_cart = false;

    // Loop through all products in the Cart
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {

    // If Cart has category “change-category-name”, set $cat_in_cart to true
    if ( has_term( ‘tarjetas-de-regalo’, ‘product_cat’, $cart_item[‘product_id’] ) ) {
    $cat_in_cart = true;
    break;
    }
    }

    // set to true if “change-category-name” is in the Cart
    if ( $cat_in_cart ) {
    return true;
    }
    }
    add_filter( ‘woocommerce_available_payment_gateways’, ‘disable_partial_payment_for_category’ );

    Thread Starter jinsley8

    (@jinsley8)

    @roberto22 I just wrote it off the top of my head. I don’t have a site setup to test it.

    I want to disable partial payment on COD orders. How can I do it? And where to put that code? Please help me, guys.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Disable partial payment for one product category’ is closed to new replies.