[Resolved] Display Woocommerce SKU

Home Forums Support [Resolved] Display Woocommerce SKU

Home Forums Support Display Woocommerce SKU

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #991984
    Jono

    Hi, I’m trying to display the SKU in the archive listing of products in Woocommerce.

    I’ve worked through https://generatepress.com/forums/topic/woocommerce-archive-pages-show-sku-3/ which is exactly what I need. But I can’t make it work!

    I’ve got the correct hook and I’ve selected Execute PHP. But it just outputs the PHP as text.. Am I missing something really obvious?

    I’ve added the staging site URL to this post.

    Many thanks.

    #992412
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Can you share the function you’re currently using?

    Let me know ๐Ÿ™‚

    #992543
    Jono

    Hey Tom, thanks for the reply. I’m using David’s code from the thread referenced above.

    add_action( 'woocommerce_single_product_summary', 'db_after_single_product_title', 6 );
    function db_after_single_product_title() { 
        // your content here
    }
    #992552
    Tom
    Lead Developer
    Lead Developer
    #992554
    Jono

    Thanks Tom! Unfortunately not… It just adds the code as plain text in the item title link.

    https://blueislandpress.com.au/staging2019/product-category/artists/emily-hamilton/

    #992581
    Tom
    Lead Developer
    Lead Developer

    Are you adding it as a Hook Element?

    If so, try this instead:

    <?php
    global $product;
    echo '<span class="custom_sku">Part no. ' . $product->get_sku() . '</span>';
    ?>

    And make sure “Execute PHP” is checked.

    #993378
    Jono

    Perfect!! Thanks so much Tom.

    #993897
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.