vendredi 27 février 2015

WooCommerce Extra Fee

I have found this snippet of code which works perfectly, but its adding a 0.5% fee per product added to the basket in the category of 19, instead of having is as a percentage, I need a round figure.



function df_add_ticket_surcharge( $cart_object ) {

global $woocommerce;
$specialfeecat = 19; // category id for the special fee
$spfee = 00.00; // initialize special fee
$spfeeperprod = 0.05; //special fee per product

foreach ( $cart_object->cart_contents as $key => $value ) {

$proid = $value['product_id']; //get the product id from cart
$quantiy = $value['quantity']; //get quantity from cart
$itmprice = $value['data']->price; //get product price

$terms = get_the_terms( $proid, 'product_cat' ); //get taxonamy of the prducts
if ( $terms && ! is_wp_error( $terms ) ) :
foreach ( $terms as $term ) {
$catid = $term->term_id;
if($specialfeecat == $catid ) {
$spfee = $spfee + $itmprice * $quantiy * $spfeeperprod;
}
}
endif;
}

if($spfee > 0 ) {

$woocommerce->cart->add_fee( 'Ticket Concierge Charge', $spfee, true, 'standard' );
}

}

add_action( 'woocommerce_cart_calculate_fees', 'df_add_ticket_surcharge' );


Weather there is 10 or 1000 products of a certain category in the basket, the fee just needs to be a total sum of £10.


Aucun commentaire:

Enregistrer un commentaire