Adding a Fee in Woocommerce

This piggybacks off of a solution I found elsewhere. We modified it to add a single fee for products based on the taxonomy. It comes in handy to categories products and then apply this rule to that category.

function action_woocommerce_checkout_calculate_fees( $cart ) {

// Initialize
$quantity = 0;
$hasfee = 0;
$fee = 0;
// Loop though each cart item
foreach ( $cart->get_cart() as $cart_item ) {
// Compare
$quantity = 0;
$product_id = $cart_item[‘product_id’];
$quantity = $cart_item[‘quantity’];
$taxonomy = ‘product_tag’;
if( has_term( ‘Embroidery’, $taxonomy, $product_id ) ){
if( !has_term( ‘NOE’, $taxonomy, $product_id ) ){
// Addition
// Get product quantity in cart
$hasfee = 1;
$fee = $fee + (4.99 * $quantity);
}
}
}
if($hasfee == 1){
$cart->add_fee( __( ‘Embroidery Fee’, ‘woocommerce’ ), $fee );
}

}
add_action( ‘woocommerce_cart_calculate_fees’, ‘action_woocommerce_checkout_calculate_fees’, 10, 1 );

 

More Web Design Blog Content

Sullivan Welding Has A New Website

Sullivan welding does excellent custom welding and fabrication. Willum is the owner and manages a crew of expert custom welders. He came to Livewire looking for the best in Gainesville Web Design and we were able to set him up in a great new website in just a

Haile’s Angels Pet Rescue has a New Website

Customized WP theme – a great choice for a great organization. Haile’s Angels continues to do some great work in our community focusing on our four legged friends. They take in a good number of pets each month and try to find them forever homes. As a no-kill

Review: WordPress Business Directory ★ ★ ★

[vc_row][vc_column width=”1/3″][vc_button title=”Where it’s at” target=”_blank” color=”btn-inverse” icon=”wpb_arrow” size=”wpb_regularsize” href=”http://codecanyon.net/item/wp-business-directory/2203258″][vc_column_text] ★ ★ ★ Features V1.8 Premium Membership (Paypal) Location Based Search Internationalization CSV Import with auto map location finder[/vc_column_text][/vc_column][vc_column width=”1/3″][vc_column_text] 3 Stars out of 5 This is a wordpress plugin We took off one point for poor style

Why are most government websites so terrible?

The recent debacle with the Affordable Care Act has made headlines but those of us in the development world are just seeing more of the same old thing. Government websites stink! Why is that? I can assure you that their cost structure is very similar to the outrageous

Are You Using Linkedin Like You Should?

Probably not. Linkedin is a valuable resource for any professional, but particularly freelancers and business owners. There is a lot to love about the social media construct, and a lot to hate; but no matter what side of the coin you fall on it is no secret that you

When To Get A New Mac

When To Get A New Mac

MacBook Running Hot and Sluggish? It Might Be Time for a New One If your MacBook Pro has started running hot, fans are constantly spinning, and everything from Safari to Finder feels like it’s stuck in molasses—you’re not alone. These are some of the most common signs that