Support » Plugin: WooCommerce Pay for Payment » Zero charge for certain items

  • Resolved lh23

    (@lh23)


    Hi Karolina,
    I have some free virtual products in my store. Usually this isn’t a problem for your plugin because someone will buy them along with a paid product. However sometimes they will buy only the free item and are being charged a 30 cent fee (the fixed charge part of the fee).

    Is there a way to disable charging a fee on a per-product basis?

    Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Karolina Vyskocilova

    (@vyskoczilova)

    Hi @lh23,

    have a look on following filter and implement it as you want 🙂

    https://github.com/vyskoczilova/woocommerce-payforpayment#filter-woocommerce_pay4pay_apply

    Best regards,
    Karolina

    Thank you for the reply, that may be beyond my abilities but I will play around with it sometime!

    Thanks for the plugin as well.

    Hi Karolina, I don’t expect you to offer free support but thought I would ask. I am trying this code and getting errors, but I am guessing at some of the terms:

    /** Woocommerce – don’t add Stripe fee if only a free purchase
    */
    function my_pay4pay_handle_free( $do_apply , $amount , $cart_subtotal , $current_payment_gateway ) {
    if ( amount_is_0() )
    return false;
    else
    return $do_apply;
    }
    add_filter( “woocommerce_pay4pay_apply”, ‘my_pay4pay_handle_free’ , 10 , 4 );

    Plugin Author Karolina Vyskocilova

    (@vyskoczilova)

    Hi @lh23, could you send me as well the amout_is_0() function? I will test it.

    Hi @vyskoczilova,
    I am just trying to tell it that if the cart subtotal is zero, not to apply the fee.

    /** Woocommerce – don’t add Stripe fee if only a free purchase
    */
    function my_pay4pay_handle_free( $do_apply , $amount , $cart_subtotal , $current_payment_gateway ) {
    if ($cart_subtotal == 0)
    return false;
    else
    return $do_apply;
    }
    add_filter( “woocommerce_pay4pay_apply”, ‘my_pay4pay_handle_free’ , 10 , 4 );

    I think the two things I’m having trouble with are getting the cart subtotal:
    if ($cart_subtotal == 0)
    I have also tried: WC()->cart->subtotal == 0

    Also, does this code go in functions.php or class-pay4play.php

    Thanks again

    Plugin Author Karolina Vyskocilova

    (@vyskoczilova)

    Hi @lh23,

    I understood what are you trying to achieve, but I wanted to know how it was checked to be able to catch the problem. This one should work fine for you:

    /** Woocommerce – don’t add Stripe fee if only a free purchase
    */
    function my_pay4pay_handle_free( $do_apply , $amount , $calculation_base , $current_payment_gateway ) {
    	
    	$cart = WC()->cart;
    	
    	if ( wc_prices_include_tax() ) {
    		$subtotal = intval( $cart->subtotal );
    	} else {
    		$subtotal = intval( $cart->subtotal_ex_tax );
    	}
    	
    	if ($subtotal == 0) {
    		return false;	
    	} else {
    		return $do_apply;
    	}
    }
    add_filter( "woocommerce_pay4pay_apply", "my_pay4pay_handle_free" , 10 , 4 );

    Add it to your functions.php.

    Have a nice weekend!
    Karolina

    That did it! Thank you so much. Same to you!!

    Plugin Author Karolina Vyskocilova

    (@vyskoczilova)

    Great! If you are enjoying my support, feel free to give a review or donation for plugin development.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Zero charge for certain items’ is closed to new replies.