Featured Image WooCommerce Add Handling Fee For Orders Over Specific Amount

WooCommerce Add Handling Fee For Orders Over Specific Amount

Cabe Nolan Author
Cabe Nolan April 16, 2018

Share:

This post was originally created on our sister site WP Cover.
View Original Article

Today I’m sharing a quick code snippet that was recently implemented for one of my clients.  The client has a WooCommerce powered online store and has found a very successful niche.  He often ships fragile goods and when the orders get large, it takes extra time to pack, handle, and ship the goods.  He requested the addition of a $10.00 handling charge for orders where the sub-total was greater than $100.

Easy enough!

With a little thought and some quick research, we implemented the following custom function in the active themes functions.php file:


add_action( 'woocommerce_cart_calculate_fees','wpcover_handling_fee' );
function wpcover_handling_fee() {
     global $woocommerce;
 
     if ( is_admin() && ! defined( 'DOING_AJAX' ) )
          return;
          $subtotal = WC()->cart->get_subtotal();
          //set our subtotal amount
		    if($subtotal > 100) {
			    //set our fee amount
		     	$fee = 10.00;
		     	//you can change the title of the fee as it appears in the cart
		     	$woocommerce->cart->add_fee( 'Handling', $fee, true, 'standard' );
		    }
}

That’s all there is to it! Enjoy.

The post WooCommerce Add Handling Fee For Orders Over Specific Amount appeared first on WP Cover.

Share:

Cabe Nolan Author Image
Written by

Cabe Nolan