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
contractor website design

Why Contractors Need Professional Website Design to Stay Competitive

In today’s digital-first world, a contractor’s website is more than just an online presence—it’s a powerful tool to attract, engage, and convert potential clients. Whether you’re a general contractor, plumber, electrician, or specialize in any other trade, having a well-designed website can set you apart from competitors and

Using Zapier and ChatGPT

Here are some powerful and practical Zapier + ChatGPT workflow ideas across a variety of use cases — ideal for small businesses looking to automate content creation, customer service, and lead handling: ✉️ 1. Auto-Reply to Form Submissions with Personalized Emails Trigger: New form submission via Webflow, Typeform,

CSS Evolution

Cascading Style Sheets, or CSS revolutionized the way the web was/is written. The next evolution has been the roll out of CSS3. With all kinds of new tricks, CSS3 promises to take web programming to the next level … and beyond. We generally hand code all of our

How To Win Visitors And Influence Traffic

Is there anything more of a turn-off than a untrustworthy website? Not in our world. Increasing the trust in your website is key to making conversions (calls, emails…. sales … you know, money). There are a number of factors determining the level of trust on your website. Here’s

Conversion Optimization

So many people have a myopic outlook on SEO and SEM. They tend to focus on optimization as strawberry field, where you can just pick a little fruit from here or there and fill up your basket. Not so fast. It’s not just about having a full basket,