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

Northwest Seafood has a new website!

Thanks to our killer Gainesville Web Design another Gainesville company has joined the livewire family with a brand new website! It’s wordpress so we can’t take credit for the design in it’s entirety but the layout is great and they’re very happy with the finished product. Their original

Review: PHP Live Chat ★★★★

4 Stars for this chat system from GNTStudio. It’s quite useful and very easy to install. We’re actually planning to use it on our own website we like it so much. They lose one star because we had to modify a bit too much to get things to

Fraternity Management Has a New Website

Fraternity management needed something up quickly and something that was affordable. Glad to know that they chose us as their Gainesville Web Design team.  Additional to the website they requested a simple program that managed their payment modules. As experienced PHP developers, we were able to quickly put

Search Engine Optimization

More important than ever and we’re at the leading edge. One of our best success stories is Rose Petals Nursery. We’ve been doing optimization for them for some time now with some great results. We’re dominating from top to bottom. Just check out this high level, competitive keyword: Old Garden

Choosing The Right Domain

Finding the right domain can be a arduous process. That is, unless of course you are lucky enough to find your business name in the exact form you desire. More often than not, obtaining a great domain takes a lot f time, mental energy and cautious anxiety. Will

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