admin管理员组

文章数量:1323723

I want to be able to use the product variables across all templates. Where should I store them? In Woocommerce templates folder? Example:

$productTitle = $product->get_name(); $productSlug = $product->get_slug();

I need to be able to echo these variables and I don't want to declare them more than once. <h3> $productTitle </h3>

What's the better and cleaner way of doing it?

Thank you

I want to be able to use the product variables across all templates. Where should I store them? In Woocommerce templates folder? Example:

$productTitle = $product->get_name(); $productSlug = $product->get_slug();

I need to be able to echo these variables and I don't want to declare them more than once. <h3> $productTitle </h3>

What's the better and cleaner way of doing it?

Thank you

Share Improve this question asked Sep 12, 2020 at 10:59 Carla GoncalvesCarla Goncalves 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Is there a particular reason why you would like to "store" them? If not, you can simply do it like this:

<h3><?php echo esc_html( $product->get_name() ); ?></h3>

本文标签: Best way to declare product variables in woocommerce theme development