• Resolved danieldude

    (@danieldude)


    I am trying to display the shipping name to the single-product meta-description right below the SKU. so i added this code to meta.php:
    <?php echo $product->get_shipping_class(); ?>
    the problem with this is that it shows the slug of the shipping class and not the title.

    So for example the shipping class is “UPS express shipping” it will display the slug: “ups-express-shipping” this does not look good.

    Especially when the slug is in another language then I get some code instead of that language. All this would not happen if i could get the shipping class title and not the slug.

    Can anyone please help me and tell me what do i need to do so the shipping class will display instead of the shipping slug?

    Daniel

    https://www.ads-software.com/plugins/woocommerce/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Use that in combination with https://codex.www.ads-software.com/Function_Reference/get_term_by to get the full term details.

    Thread Starter danieldude

    (@danieldude)

    ?? I really tried… I’m not a php expert I’m corrently trying to learn but I did not fully understand what am I doing wrong?

    it seems that the id is the defaul value and if i want to change it i need to add the value im looking for in the ‘()’ but it didnt wok…

    I tried
    <?php echo $product->get_shipping_class($field, ‘name’); ?>
    <?php echo $product->get_shipping_class(‘name’); ?>

    none of theme work, still showing the slug… (at least it does not show an error like some other things i tried)

    Can you please help me out here?

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    $class_id = $product->get_shipping_class_id();
    $term      = get_term_by( 'id', $class_id, 'product_shipping_class' );
    echo $term->term_name;
    Thread Starter danieldude

    (@danieldude)

    Hi Mike thank you so much for your help but this code isn’t outputting anything… its blank
    I added

    <?php

    and

    ?>

    to your code and put it in the meta.php file for some reason its not working.

    <div class="product_meta">
    
    	<?php do_action( 'woocommerce_product_meta_start' ); ?>
    
    	<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
    
    		<div class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'n/a', 'woocommerce' ); ?></span>.</div>
        shipping:
        <?php $class_id = $product->get_shipping_class_id();
    $term      = get_term_by( 'id', $class_id, 'product_shipping_class' );
    echo $term->term_name; ?>
    
    	<?php endif; ?>

    could it be an issue with my theme?

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Sorry, term_name should have been name.

    Thread Starter danieldude

    (@danieldude)

    You rock Mike!!! Thank you!!!

    I’m trying to show the same thing on the checkout page. I’ve tried the code Mike suggested above in the cart-shipping.php file, but it doesn’t work.

    I’ve got 4 shipping classes set under the flat_rate shipping method and I’d like to show the shipping class name next to each one on the checkout when the user buys products with each shipping class. Right now it just shows ‘Flat rate’ for each item, but it would be better if it also shows the class name.

    Great job Mike…

    But let me motivate you to do even better… What about the ‘cost_per_order’ for the shipping class, how to display that one?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘showing shipping class name in product meta’ is closed to new replies.