I'm trying to add a class to the body of the page if a visitor is within a specific shipping option when on the Woocommerce checkout page. I've done the below but it's not adding the class? Can anyone help please?
add_filter( 'body_class', 'bbloomer_wc_product_cats_css_body_class' );
function bbloomer_wc_product_cats_css_body_class( $classes, $available_gateways ){
global $woocommerce;
$chosen_titles = array();
$available_methods = $woocommerce->shipping->get_packages();
$chosen_rates = ( isset( $woocommerce->session ) ) ? $woocommerce->session->get( 'chosen_shipping_methods' ) : array();
foreach ($available_methods as $method)
foreach ($chosen_rates as $chosen) {
if( isset( $method['rates'][$chosen] ) ) $chosen_titles[] = $method['rates'][ $chosen ]->label;
}
if( in_array( 'Delivery price on request', $chosen_titles ) ) {
$custom_terms = get_the_terms(0, 'product_cat');
if ($custom_terms) {
foreach ($custom_terms as $custom_term) {
$classes[] = 'delivery-not-available';
}
}
}
return $classes;
}