Support » Plugin: TeraWallet - For WooCommerce » How to disable partial payment for products that cannot be purchased with wallet

  • 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 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Subrata Mal

    (@subratamal)

    @sadiqodunsi

    Use below code.

    add_filter('is_enable_wallet_partial_payment', '__return_false');

    Thank you.

    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 6 months, 3 weeks ago by 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.

    /**
     * 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;
    	}
    }
    sadiqodunsi

    (@sadiqodunsi)

    Hello,

    I am still waiting for your response.

    Thanks
    Sadiq

    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://wordpress.org/plugins/payment-gateways-per-product-categories-for-woocommerce/

    • This reply was modified 2 months, 1 week 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’);

    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’);

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

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