[Support request] Show Block Element by Wocommerce Shipping Class

Home Forums Support [Support request] Show Block Element by Wocommerce Shipping Class

Home Forums Support Show Block Element by Wocommerce Shipping Class

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1926407
    Martyn

    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

    #1926892
    Elvin
    Staff
    Customer Support

    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/

    #1942104
    Martyn

    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

    #1942125
    Leo
    Staff
    Customer Support

    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 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.