In WooCommerce, I am trying to set a progressive shipping cost based on 10% of cart subtotal with $5 as minimum cost, up to $11 max cost.
Here is my code attempt:
add_filter( 'woocommerce_package_rates', 'woocommerce_package_rates', 10, 2 );
function woocommerce_package_rates( $rates, $package ) {
// Make sure flat rate is available
if ( isset( $rates['flat_rate:24'] ) ) {
// Set the cost to $5
$rates['flat_rate:24']->cost = 5;
}
$cart_subtotal = $WC()->cart->subtotal
if ($cart_subtotal >50)
$percentage = 0.10; // Percentage (10%) in float
$percentage_fee = ( WC()->cart->subtotal >+ WC()->cart->get_shipping_total()) * $percentage;
}
});
return $rates;
}
This code gives a critical error on the website. I am quite new to Wordpress custom coding as you will probably tell from the code below.
Also I would like the displayed label to show "USPS" instead of "Flat rate".
For example, if the cart subtotal is $60, they would be charged $6 flat rate shipping cost (10% of subtotal).
What am I missing or doing wrong?
