0

I've configure shipping class for my products. But I want to display them below each product in the shopping cart page. Something like this : woocommerce

I'm new in customising wordpress. Any guidance on this would be much appreciated.

Thanks!

  • how did you configure shipping class ? custom field ? – melvin Jan 20 '18 at 10:53
  • WooCommerce settings > Shipping > Shipping Class – scholarwithfire Jan 20 '18 at 13:07
0

You can try using a custom function hooked in woocommerce_cart_item_name filter hook, this way:

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;">
        <strong>' .$label . ': </strong>' . $shipping_class_term->name . '</p>';
}

Add this to your functions.php file of the active theme. Tested on Woocommerce 3.5.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.