Add a custom fee to the cart in WooCommerce

This code snippet adds a custom fee to the cart in WooCommerce. The fee is $5 and is labeled "Custom".

PHP

add_action( 'woocommerce_cart_calculate_fees', 'custom_fee' );

function custom_fee() {
  global $woocommerce;

  if ( is_admin() && ! defined( 'DOING_AJAX' ) )
     return;

  $woocommerce->cart->add_fee( __('Custom', 'woocommerce'), 5 );
}

Snippet Feedback

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

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.