Add Custom Fee to Cart

This snippet adds a custom fee to the cart total, which can be useful for handling additional charges or discounts.

PHP

function add_custom_fee() {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    WC()->cart->add_fee( 'Custom Fee', 5.00 );
}
add_action( 'woocommerce_cart_calculate_fees', 'add_custom_fee' );

Snippet Feedback

Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.

Tags

Language

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.