Archived topic
Show Block Element by Wocommerce Shipping Class
3 replies · Started by Martyn on September 10, 2021
Hi Guys,
Is there a way to show and Block Element on products pages with certain woocommerce shipping classes?
At the moment we are using inclusions and exclusions for product categories but it is becoming complex and the shipping class would simplify this.
Cheers,
Marty
Hi Martyn,
With the current options on the display rule location, I believe it's limited to Product taxonomies like tag or categories.
I'm not exactly sure but if I remember it right, shipping class, like variants are product meta. For this one, you may have to do things using generate_element_display. https://docs.generatepress.com/article/generate_element_display/
Thanks Elvin,
Would it look like:
add_filter( 'generate_element_display', function( $display, $element_id ) {
if ( 1478236 === $element_id && shipping class ( 'regular' ) ) {
$display = true;
}
return $display;
}, 10, 2 );
Cheers,
Marty
Hmm there shouldn't be a space between shipping class.
Looking at this example here:
https://stackoverflow.com/questions/53258868/conditional-free-shipping-based-on-shipping-class-and-minimal-amount-in-woocomme
So try something like this:
add_filter( 'generate_element_display', function( $display, $element_id ) {
if ( 1478236 === $element_id && 'regular' == $shipping_class ) {
$display = true;
}
return $display;
}, 10, 2 );
If not then you might need to check with WooCommerce to determine the correct conditional tag to use :)