I'm trying to find a function that automatically adds a fee to the cart if the height of the products in it is over 2,9 cm.
I'm using Woocommerce for our simple non-profit comic bookstore. We use weight based shipping as a standard in Sweden, with a bulky fee if something is 3 cm or over.
I've tried modifying this answer of LoicTheAztec regarding fees based on total cart weight, but I really don't know what I'm doing as I am getting a blank page after saving the code.
The code I'm trying to modify is this one:
add_action( 'woocommerce_cart_calculate_fees', 'shipping_weight_fee', 30, 1 );
function shipping_weight_fee( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// Convert cart weight in grams
$cart_weight = $cart->get_cart_contents_weight() * 1000;
$fee = 50; // Starting Fee below 500g
// Above 500g we add $10 to the initial fee by steps of 1000g
if( $cart_weight > 1500 ){
for( $i = 1500; $i < $cart_weight; $i += 1000 ){
$fee += 10;
}
}
// Setting the calculated fee based on weight
$cart->add_fee( __( 'Weight shipping fee' ), $fee, false );
}
My experience with php is not more than being able to paste actions into my child-theme's functions.php.
I appreciate any help I can get.