Show SKU # on Product List - by pensline

This topic has 4 replies, 2 voices, and was last updated 7 years, 8 months ago ago by Jack Richardson

  • Avatar: pensline
    pensline
    Participant
    August 25, 2016 at 18:57

    is it possible to show the sku # alongside the product name in the items list?

    We’d like to show:

    Product Picture
    Product Name
    Sku #
    Price

    3 Answers
    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    August 25, 2016 at 20:04

    Hello,

    Try the following code in functions.php:

    add_action( 'woocommerce_after_shop_loop_item_title', 'shop_sku' );
    function shop_sku(){
    global $product;
    echo '<span itemprop="productID" class="sku">SKU: ' . $product->sku . '</span>';
    }

    We recommend to add it in child theme functions.php file https://codex.wordpress.org/Child_Themes

    Best regards,
    Jack Richardson.

    Avatar: pensline
    pensline
    Participant
    August 29, 2016 at 22:20

    Thank you that worked. How can center it with the rest of the text?

    Avatar: Jack Richardson
    Jack Richardson
    Support staff
    August 30, 2016 at 08:55

    Hello,

    In this case edit the previous code to this:

    add_action( 'woocommerce_after_shop_loop_item_title', 'shop_sku' );
    function shop_sku(){
    global $product;
    echo '<div itemprop="productID" class="sku">SKU: ' . $product->sku . '</div>';
    }

    and add this code in style.css of your child theme or in custom.css file of the parent theme:

    .sku {
        text-align: center;
    }

    Best regards,
    Jack Richardson.

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.