Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor podpirate

    (@podpirate)

    Hi,
    the filter name you are using only applies when cash on delivery payment is selected. (That’s what the cod in woocommerce_pay4pay_cod_amount stands for).

    You probably want to use woocommerce_pay4pay_apply, which works independent from the current payment method. So the last line of your PHP whould read:

    add_filter('woocommerce_pay4pay_apply','free_payment_on_free_shipping');

    Also the if ( in_array( ... line is missing a closing bracket ) which very likely has caused a blank-screen-of-death.

    To your other questions:

    1. To add the fee only on checkout instead of the cart

    The plugin starts working every time when the cart is calculated and a payment method is known. Basically It’s calculating and adding an extra fee to the cart. This works independently from woocommerce current page (be it cart, checkout, shop, …), and turned out to be the most robust solution. I’m somewhat afraid to mess around with it…

    You could try to use the above filter and return false when woocommerce is not on the checkout page. Should go like this (Caution! You should check if the payment fee is still there, after the order has been placed):

    function wc_pay4pay_only_on_checkout( $do_apply ) {
            if ( is_checkout() )
                return $do_apply;
            return false;
        }
        add_filter('woocommerce_pay4pay_apply','wc_pay4pay_only_on_checkout');

    2. To disable the fee on not only on free shipping but on delivery options that will have no cost ??

    “free shipping” in woocommerce is a shipping method of its own and is something different than “shipping cost calculation yields 0.00 Bucks”. The plugin is currently checking for that one shipping method, but does not consider the actual shipping cost.

    I will put on my thinking cap about this…

    best regards,
    j?rn

    Thread Starter Filipe Costa

    (@filipecostacom)

    Hi, the first code i provided works, it was just the closing bracket that was missing, thanks!

    However i’m unable to add more than one delivery method. Here is the line:

    if ( in_array( ‘local_pickup’,’local_delivery’ , WC()->session->get( ‘chosen_shipping_methods’ ) ) )

    To solve this i have duplicated the functions, one for local_pickup and one for local_delivery. Maybe you can help about adding both delivery options on that line?

    The second function, to show only on checkout hiding on cart didn’t work, because the fee wasn’t being added even when i was on checkout. However i think i was able to do it:

    function wc_pay4pay_hide_on_cart( $do_apply ) {
    if ( is_cart() )
    return false;
    return $do_apply;
    }
    add_filter(‘woocommerce_pay4pay_apply’,’wc_pay4pay_hide_on_cart’);

    Its like your code, but instead of applying on checkout it just hides the fee on cart ??

    Thanks a lot!! This is the only fee plugin for WooCommerce that allows me to apply a fee or discount, but disable it on specific delivery methods!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘No fee on some shipping options and add fee only on checkout’ is closed to new replies.