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 );

 

Answerhub versus WordPress

Recently we worked on a project with intent to use AnswerHub as the primary vehicle for user interaction. After spending some time in AnswerHub’s admin

Read More »

Review: WordPress Business Directory ★ ★ ★

[vc_row][vc_column width=”1/3″][vc_button title=”Where it’s at” target=”_blank” color=”btn-inverse” icon=”wpb_arrow” size=”wpb_regularsize” href=”http://codecanyon.net/item/wp-business-directory/2203258″][vc_column_text] ★ ★ ★ Features V1.8 Premium Membership (Paypal) Location Based Search Internationalization CSV Import with

Read More »

Raven Tools

Took a look at Raven SEO tools today. Really, not all that impressed. They have a good price but it mostly looks like you’re just

Read More »