I have created a webshop in Woocommerce (wordpress) It is a liquor store and I need to add an extra cost: 0,08 euros per bottle (product).
I've found it and adjusted it, but I get an additional line in the cart to multiply the number of bottles (0.08) with the price of 0.08, but the value is 0.
Can anyone tell me what I am doing?
function get_cart_contents_count () {return_filters ('Woocommerce_cart_contents_count', $ this- & gt; cart_account_count); } Function woo_add_cart_fee () {global $ woocommerce; $ Woocommerce- & gt; Cart- & gt; Ad_fe (__ ('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 apply to all cartons
// Hook before adding fee addition ('woocommerce_cart_calculate_fees', 'add_custom_fees'); Function add_custom_fees (WC_Cart $ cart) {$ charge = 0.08; $ Cart- & gt; Add_f ('handling fee', $ fee); }
Edit: To multiply it with each product
add_action ( 'Woocommerce_cart_calculate_fees', 'add_custom_fees'); Function add_custom_fees (WC_Cart $ cart) {$ fees = 0; Forex Currency ($ Cart-> Get_cart () $ items) {$ charge = $ item ['Quantity'] * 0.08; } If ($ charge! = 0) {$ Cart-> Plus_f ('handling fee', $ fee); }}
No comments:
Post a Comment