I've created a webshop in Woocommerce (wordpress). It's a wine shop and I need to add an extra cost: 0,08 euro per bottle (product).
I've found this and adjusted it, but I cannot get the number of products (bottles) to multiply with 0.08 euro. In the cart I do get an extra line but the value is 0.
Can anyone explain me what I'm doing wrong?
function get_cart_contents_count() {
return apply_filters( 'woocommerce_cart_contents_count', $this->cart_contents_count );
}
function woo_add_cart_fee() {
global $woocommerce;
$woocommerce->cart->add_fee( __('Custom', 'woocommerce'), $get_cart_contents_count * 0.08 );
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
Try this code in your functions.php but it will be applied on over all cart
EDIT: To multiply it with each product do something like
You are talking about adding surcharge to the cart. You can get all the related information from the Woocommerce Doc in here.