• Resolved sabbibalam123

    (@sabbibalam123)


    Hi Great Minds,

    // Add a custom fee based o cart subtotal
    add_action( 'woocommerce_cart_calculate_fees', 'custom_fee', 20, 1 );
    function custom_fee ( $cart ) {
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    
        if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) )
            return; // Only checkout page
    
        $payment_method = WC()->session->get( 'chosen_payment_method' );
    
        if ( 'pay_gateway_ideal' == $payment_method ) {
            $surcharge = $cart->subtotal * 0.0331700;
            $cart->add_fee( 'Spraypay Betaal in 1 tm 36 termijnen', $surcharge, true );
        }
    }

    In this code $cart->add_fee simply SUM up the fee with SUBTOTAL, But here’s my Question, I am not sure if its possible or not.. I don’t like to SUM up it with SUBTOTAL. I just need it to be A info, which should not Effect the Total Cart Price.
    Any Solution???
    Thanks in Advance..

Viewing 9 replies - 1 through 9 (of 9 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @sabbibalam123!

    If I understand correctly, you would like to add this additional fee, but at the same time NOT add the fee/ Instead, you would like to display a notice where the fee should be?

    In order for me to help better, I would need to get a better understanding of what exactly you are trying to achieve here and what you need the end result/s to be. Please let me know.

    Cheers!

    Thread Starter sabbibalam123

    (@sabbibalam123)

    @rynald0s thanks for your reply.
    Yes Fees will be calculated and displayed but i don’t want it to be sum with subtotal.
    So,
    if the subtotal is 10$
    Fee is 5$
    The final cart amount should be 10$ instead of 15$, ignoring 5$ additional fee.

    5$ additional fee is just a NON EFFECTED CALCULATED field for the customer.

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @sabbibalam123!

    OK, there is one way to achieve this, which might be a bit messy, but it is a workaround.

    You can add the same fee twice. Yes, as both a positive and a negative. Look at the following code as an example:

    add_action( 'woocommerce_cart_calculate_fees','wc_add_surcharge' ); 
    function wc_add_surcharge() { 
    global $woocommerce; 
    
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 
    return;
    
    $county = array('US');
    $fee = 6.00;
        
    if ( in_array( WC()->customer->get_shipping_country(), $county ) ) : 
        $surcharge = ( $fee );
        $woocommerce->cart->add_fee( 'Spraypay Betaal in 1 tm 36 termijnen', $surcharge, true, '' );
    endif;
    }
    
    add_action( 'woocommerce_cart_calculate_fees','wc_add_negative_fee' ); 
    function wc_add_negative_fee() { 
    global $woocommerce; 
        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 
            return;
        $fee = -6.00;
        $woocommerce->cart->add_fee( 'Minus Fee', $fee, false, '' );  
    }
    

    You can then hide the second fee by using some CSS code. for that, you would need to inspect the element in the cart/checkout pages and apply the correct CSS.

    It will now add the fee, but not display it with the subtotal.

    Thread Starter sabbibalam123

    (@sabbibalam123)

    I am wonder if you help me to add the css?

    
    					<tr class="fee">
    				<th>Spraypay Betaal in 1 tm 36 termijnen</th>
    				<td><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&euro;</span>31.51</span></td>
    			</tr>
    					<tr class="fee">
    				<th>Spraypay Betaal in 1 tm 36 termijnen neg</th>
    				<td><span class="woocommerce-Price-amount amount">-<span class="woocommerce-Price-currencySymbol">&euro;</span>31.51</span></td>
    			</tr>

    when i change display none for fee it hide both option, but i just need to hide ‘Spraypay Betaal in 1 tm 36 termijnen neg’

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @sabbibalam123!

    Please link me to your site so I can take a closer look. You need to target and copy the specific selector.

    Cheers!

    Thread Starter sabbibalam123

    (@sabbibalam123)

    Here is the site
    Please have a look.

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @sabbibalam123!

    OK, so the correct CSS to use here would be:

    #order_review > table > tfoot > tr:nth-child(3) {
        display: none;
    }

    Cheers!

    Thread Starter sabbibalam123

    (@sabbibalam123)

    That is awesome.
    Thanks a lot @rynald0s <3

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    You are very welcome, @sabbibalam123!

    Please stay safe and have a fantastic day further.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘If there’s any way to show non effect additional fee’ is closed to new replies.