I have a scenario where I need to remove the "Place order" button on the checkout screen for Woo-commerce.
Currently I have 2 shipping methods: Flexible shipping and Freight
If a customer adds an item with the shipping class of "Freight" to their cart, my current code disables the flexible shipping method and then the freight method displays a message of "Call for current rates".
The issue is that they can still checkout essentially without paying anything for shipping which is why if freight is the only shipping method available I need the place order button to be removed or replaced.
Here is the code I am currently using and trying to modify unsuccessfully:
add_filter( 'woocommerce_package_rates', 'wc_hide_free_shipping_for_shipping_class', 10, 2 );
function wc_hide_free_shipping_for_shipping_class( $rates, $package ) {
$shipping_class_target = 332;
$in_cart = false;
foreach( WC()->cart->cart_contents as $key => $values ) {
if( $values[ 'data' ]->get_shipping_class_id() == $shipping_class_target ) {
$in_cart = true;
break;
}
}
if( $in_cart ) {
unset( $rates['flexible_shipping_7_2'] );
}
return $rates;
}
Is there a simple hook or something I'm missing?
I've been messing with this for a while and am hitting a wall.
Try the following, that will output an inactive greyed "Place Order" order button when a specific shipping class is found in cart items:
Code goes in function.php file of your active child theme (or active theme). Tested and works.
To remove completely the "Place order" button, you will use this similar instead:
Code goes in function.php file of your active child theme (or active theme). Tested and works.