SKU shortode
-
Hi there,
I’m using the code below in my functions.php to be able to output the SKU in various places all over my templates with[woo_sku]
. While this works fine, I can’t access the template editor (elementor) without uncommenting the function, as there is no product context in the template and the error prevents the editor from loading.Is there a way to catch the error and return an empty value when not in a product context?
function display_woo_sku() { global $product; return $product->get_sku(); } add_shortcode( 'woo_sku', 'display_woo_sku' );
Cheers,
-martin
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘SKU shortode’ is closed to new replies.