D
D
Denis Petrovsky2016-11-19 04:39:50
WordPress
Denis Petrovsky, 2016-11-19 04:39:50

How to display the shipping class in the product card?

The night is half the night, and even I can’t sleep .. I can’t help but figure it out, make me think ..
Here the product is individually assigned a delivery class (in the product editor)
How can I display this value in the product map?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2016-11-20
@HeadOnFire

This value is already used in the shopping cart when choosing a delivery. However, it can be obtained separately, if necessary. The shipping class in WooCommerce is the taxonomy "product_shipping_class". To get it, use the get_terms() function:

$shipping_classes = get_terms( array(
    'taxonomy' => 'product_shipping_class',
    'hide_empty' => false,
) );

Or, if this does not work out with this taxonomy (although it should), use the WooCommerce API itself - the class can be obtained by the product's get_shipping_class() method:
global $product; // Опционально, если продукт у нас не под рукой
$shipping_class = $product->get_shipping_class();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question