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

HotOpponents Hack

We have seen this one a few times coming from WordPress but we have also seen it in Google Analytics code or simply in a header.php file. HotOpponents is a simple redirect script but really digs down and makes roots for itself throughout your website files and database. 

Date for our next Seminar is 4/8

Livewire Seminars are the perfect way to collect everything you need to know to do your own website optimization. We have what it takes to put your site on page 1 and we’ll teach you all of the not-so-secret info. Where to go, what to do, and how

Messaging When Switching From iPhone to Droid

Sneaky little issue pops up when you move away from iphone. Other iphone users that previously texted you won’t be able to text you the same way once you switch. This is because when you both were using iphones, the messaging system was not the typical SMS, but

Small Business Sees A Rise In Cyber Threats

Come on, let’s all live in the real world: we’re all vulnerable. Really the only chance you have these days is to make it as difficult as possible for any potential hacker to get to your valuable data. First and foremost this means protecting your data in transit.

Facebook Dings Developers

In the ever growing app community, Facebook is putting the screws to developers looking to use their vast resources to build their apps. Really, they’re just looking for a little “reciprocity”. But come on, how much do you need? You already own and operate the largest website in