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
Programming code on a computer screen

Simplifying JavaScript Development with Essential Tools

JavaScript is an incredibly powerful language that drives the dynamic and interactive elements of web applications. However, it can also be complex and challenging to work with, especially as projects grow in size and scope. Fortunately, there are a number of tools available that can streamline the development

Insurency SEO

Glad to have Insurency on board with the Livewire team. We did not make their website but we’ll be doing their Internet marketing. We have a great plan for them and will be proud to be competing alongside huge names like Geico and Progressive. It’s quite the challenge

No Business is too Small for Mobile

No matter how small your business is, you need to be on mobile. There are more mobile users these days than traditional desktop/laptop users, so the benefit is apparent. If your website is not mobile ready, you are at a distinct disadvantage. First, the user will probably have

Review: Google Chrome – StayFocusd ★★★★★

We. Love. This. Chrome extension. Warning: It’s brutal. Stayfocusd is essentially a task manager, not as in manage what task is next, but keeps you focused on your tasks at hand. It blocks websites that waste your time and keep you distracted through a time limit feature. You

Budding Biologist has a new website

A cute website for a really neat childrens’ book series by budding biologist. Their new website is responsive, meaning it is mobile ready and will display correctly across all devices and all browsers. Integrated web store and using the latest in HTML 5 and CSS3 media queries. Cloud

Preloading Images with Jquery

There are times when preloading images is an important step in keeping your site/page/program running smoothly. This is especially true in the era of mobile. Here’s a cute little snippet that does just that. function preload(yourarrayOfImages) { $(yourarrayOfImages).each(function(){ $(‘<img/>’)[0].src = this; }); } preload([ ‘img/image1.jpg’, ‘img/image2.jpg’, ‘img/image3.jpg’ ]);