• Resolved indienhaus

    (@indienhaus)


    Hi, we are using several shipping classes.
    It would be great if it would be possible to display the shipping class at the single product page. So the customer knows how the shown product would be delivered (DHL, forwarder, UPS, etc.)
    The best place to display the class would be the place where all attributes are shown.

    Thanks
    Max

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • I also would have liked to do the same but only came across the following which displays the Shipping Class on the Checkout Page which may help:

    https://stackoverflow.com/questions/48353893/add-shipping-class-below-each-product-in-woocommerce-shopping-cart-page

    I found this option worked the best:

    add_filter( ‘woocommerce_cart_item_name’, ‘shipping_class_in_item_name’, 20, 3);
    function shipping_class_in_item_name( $item_name, $cart_item, $cart_item_key ) {
    // Only in cart page (remove the line below to allow the display in checkout too)
    //if( ! ( is_cart() || is_checkout() ) ) return $item_name;

    $product = $cart_item[‘data’]; // Get the WC_Product object instance
    $shipping_class_id = $product->get_shipping_class_id(); // Shipping class ID
    $shipping_class_term = get_term( $shipping_class_id, ‘product_shipping_class’ );

    if( empty( $shipping_class_id ) )
    return $item_name; // Return default product title (in case of)

    $label = __( ‘Shipping class’, ‘woocommerce’ );

    return $item_name . ‘<br>
    <p class=”item-shipping_class” style=”margin:12px 0 0;”>
    ‘ .$label . ‘: ‘ . $shipping_class_term->name . ‘</p>’;
    }

    The following line is commented out using // so that the Shipping Class displays on both the Cart and Checkout page. You may want to remove // so that the Shipping Class is displayed only on the Cart Page

    if( ! ( is_cart() || is_checkout() ) ) return $item_name;

    I used Code Snippets to add this code which works fine.

    Hope this helps

    • This reply was modified 6 years, 8 months ago by aristocats.
    Thread Starter indienhaus

    (@indienhaus)

    Thanks that works for me too.

    Luminus Alabi

    (@luminus)

    Automattic Happiness Engineer

    @indienhaus,

    Glad to hear you’ve got that working.

    I’ll go ahead and mark this as resolved. If you have any further questions feel free to open a new thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display shipping class at single product page’ is closed to new replies.