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

Website Redesign Launch: Precon Tanks Gets a Modern Upgrade

We’re excited to announce the launch of the brand-new website for Precon Tanks — a leading manufacturer of precast concrete tanks and systems for the wastewater and stormwater industries. With decades of expertise and a reputation for quality and dependability, Precon needed a website that reflected their technical

The Greatest Watch In The History Of Mankind

Well, this has little … really nothing … to do with website design or SEO but we would like to take a moment to recognize the greatest wood watch in the entire world. This thing is decked out. Sleek, modern and unique. It slides on like a Gregory

Moving Your Website To A New Host

Sometimes it’s easy, most of the time it is not. What a headache! If you’ve moved hosts and domains several times you’re probably an old hand at it; if not, you’re in trouble. You’ll probably need the assistance of someone that has some experience in this area. Choosing

Using Red In Website Design

A key component of website design is color, and many designers choose the color red in particular. Red is a passionate, vivid color that may elicit strong feelings and emotions, making it a fantastic choice for designing a strong, compelling website. These are several justifications on why red

Livewire SEO

The most common question we receive following a website launch is, “How can I increase traffic to my website without spending a fortune or buying ads?” Every website we develop for a customer includes what we refer to as “Basic SEO”; this simply means that we will fill