In Italy there is a specific fee for the disposal of electronic products that must be paid during the purchase.
This "ecofee" is specific for each product.
I have set up a specific meta for each product called meta_product_grossecofee
I'd like to convert the value of this meta field in a fee on the cart.
This is the code I've tried, however without the desired result. Any advice?
add_action( 'woocommerce_cart_calculate_fees', 'ecofee_display' );
function ecofee_display(){
global $product;
$ecofee = $product->get_meta('meta_product_grossecofee');
if ($ecofee) {
WC()->cart->add_fee(__('Ecofee: ', 'txtdomain'), $ecofee);
}
}