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
web design ocala fl

Why Local Web Design Matters for Your Ocala Business

In today’s digital age, having a professional website isn’t just an option—it’s a necessity. But not all websites are created equal, especially when it comes to local businesses. If your business is based in Ocala, FL, choosing a local web design company like Livewire can make all the

Project Gutenburg

Every heard of it? If not, make sure to check it out. They have tons of books online, free for anybody. Our favorite? A Connecticut Yankee in King Arthur’s Court by Mark Twain http://www.gutenberg.org/ebooks/86 Got a smartphone? Just download a free e-reader and you’re all set. Download the

Why Website Speed Matters More Than Ever in 2024

In today’s fast-paced digital world, website speed is crucial. Users expect instant access to information, and a slow website can significantly impact your business. Here’s why website speed matters more than ever in 2024 and how you can improve it. The Importance of Website Speed User Experience When

Javascript functions, variables, objects

How JavaScript Enhances Modern Web Design and User Experience

JavaScript has transformed web design, making websites more interactive, dynamic, and user-friendly. Whether you’re running an e-commerce site, a business portfolio, or a blog, JavaScript plays a crucial role in creating a memorable user experience. In this post, we’ll explore how JavaScript can be used effectively in web

AJAX Store Locator ★★★★★

Just finished up a project using AJAX store locator from codecanyon. The client needed a lightweight solution to locate specialty stores all across the country. With some significant upgrades, we customized this script to suit their needs exactly. Customization took around six hours but was much more efficient

Is PPC Advertising Worth It?

The answer is: it depends. In our experience it really comes down to your industry, your ad’s effectiveness and … dum de dum dum … money. First, your industry should be visible online in the first place. Holly’s Bakery is probably going to do fine on Google ads