• Resolved sadiqodunsi

    (@sadiqodunsi)


    Hello,

    I have a subscription product where I want users to only pay with their bank cards not wallet. I am able to unset wallet payment for the subscription products with the following code.

    // I added a payment product category to wallet product
    function paystack_gateway_disable($available_gateways) {
        if (!is_admin()) {
        if (payments_category_is_in_the_cart()) {
                unset($available_gateways['wallet']);
            }
        }
        return $available_gateways;
    }
    add_filter('woocommerce_available_payment_gateways', 'paystack_gateway_disable');

    However, the problem I am facing is that, if a user has an amount that is below the subscription product price in their wallet. The partial payment options shows up for the user even though I have unset wallet for the product. My question now is how do I deactivate the partial payment option for my subscription products?

    Kind regards,
    Sadiq

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

    (@subratamal)

    @sadiqodunsi

    Use below code.

    add_filter('is_enable_wallet_partial_payment', '__return_false');

    Thank you.

    Thread Starter sadiqodunsi

    (@sadiqodunsi)

    Hi,

    Thank you for the quick response. I am not sure how I can use this code conditionally that it runs when a product with payment category is in cart. I already have the function to detect if payment category is in cart. I tried the following but no luck.

    // I added a payment product category to wallet product
    function paystack_gateway_disable($available_gateways) {
        if (!is_admin()) {
        if (payments_category_is_in_the_cart()) {
        unset($available_gateways['wallet']);
        add_filter('is_enable_wallet_partial_payment', '__return_false');
            }
        }
        return $available_gateways;
    }
    add_filter('woocommerce_available_payment_gateways', 'paystack_gateway_disable');

    Additionally, I noticed that even when I used your snippet directly. The partial payment text below still shows:

    %s will be debited from your wallet and %s will be paid through other payment method.

    Kind regards,
    Sadiq

    • This reply was modified 5 years, 3 months ago by sadiqodunsi.
    Thread Starter sadiqodunsi

    (@sadiqodunsi)

    Hello,

    I am still waiting to get a response from you.

    Thank you
    Sadiq

    Plugin Author Subrata Mal

    (@subratamal)

    Please let us know the definition of payments_category_is_in_the_cart function.

    Thread Starter sadiqodunsi

    (@sadiqodunsi)

    /**
     * Function to check if a specific product category is in the cart
     * Usage: if ((payments_category_is_in_the_cart())
     */
    function payments_category_is_in_the_cart() {
    	// Add your special category slugs here
    	$categories = array( 'payments' );
    
    	// Products currently in the cart
    	$cart_ids = array();
    
    	// Categories currently in the cart
    	$cart_categories = array();
    
    	// Find each product in the cart and add it to the $cart_ids array
    	foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
    		$cart_product = $values['data'];
    		$cart_ids[] = $cart_product->get_id();
    	}
    
    	// Connect the products in the cart w/ their categories
    	foreach( $cart_ids as $id ) {
    		$products_categories = get_the_terms( $id, 'product_cat' );
    
    		// Loop through each product category and add it to our $cart_categories array
    		foreach ( $products_categories as $products_category ) {
    			$cart_categories[] = $products_category->slug;
    		}
    	}
    	// If one of the special categories are in the cart, return true.
    	if ( ! empty( array_intersect( $categories, $cart_categories ) ) ) {
    		return true;
    	} else {
    		return false;
    	}
    }
    Thread Starter sadiqodunsi

    (@sadiqodunsi)

    Hello,

    I am still waiting for your response.

    Thanks
    Sadiq

    Thread Starter sadiqodunsi

    (@sadiqodunsi)

    Hello,

    I am still in need of this. Hope to get a response.

    Thanks
    Sadiq

    didnt exactly understand your issue but came across your post looking for my own solution. I was able to resolve my issue using this plugin, maybe it can help you:

    WooCommerce Payment Gateways per Product or Category
    https://www.ads-software.com/plugins/payment-gateways-per-product-categories-for-woocommerce/

    • This reply was modified 4 years, 11 months ago by namorim83.

    Did you found a workaround for this ? I got exactly the same need, i want to disable partial payment if there is a subscription product in the cart, but keep it enabled for other products.

    I found that the code add_filter(‘is_enable_wallet_partial_payment’, ‘__return_false’); won’t work inside the ‘woocommerce_available_payment_gateways’ filter.

    The following code : add_filter(‘woo_wallet_disable_partial_payment’, ‘__return_true’); works fine if called inside :
    add_action( ‘woocommerce_cart_calculate_fees’,’Your_function_to_check_category_in_cart’);

    • This reply was modified 4 years, 10 months ago by Fabrice ESQUIROL. Reason: typo

    So following your code, this should work for you :

    function disable_partial_payment() {
    if (payments_category_is_in_the_cart()) {
    add_filter(‘woo_wallet_disable_partial_payment’, ‘__return_true’);
    }
    }
    add_action( ‘woocommerce_cart_calculate_fees’,’disable_partial_payment’);

    Thread Starter sadiqodunsi

    (@sadiqodunsi)

    Thank you very much for taking the time to help. I will give this a try later.

    Hi @creaweb2b . Thanks for This Code: add_filter(‘woo_wallet_disable_partial_payment’, ‘__return_true’);

    It worked for me but I had to Modify it first by changing ‘ to ‘ as seen below.

    add_filter(‘woo_wallet_disable_partial_payment’, ‘__return_true’);

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘How to disable partial payment for products that cannot be purchased with wallet’ is closed to new replies.