Archived topic
Display Woocommerce SKU
7 replies · Started by Jono on August 23, 2019
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.
Hi there,
Can you share the function you're currently using?
Let me know :)
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
}
What about this one?: https://generatepress.com/forums/topic/woocommerce-archive-pages-show-sku-3/#post-619232
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/
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.
Perfect!! Thanks so much Tom.
You're welcome :)