Reputation: 1409
At the bottom of every product I want to add the sentence:
Any Questions about "Product Name", get in touch with us
The code I'm using is
<h1>Questions about <?php the_product); ?> get in touch</h1>
This however doesn't seem to work, how do I pull the product name in Woocommerce?
Upvotes: 4
Views: 42418
Reputation: 383
<?php $args = array('post_type' => 'product',
'posts_per_page' =>-1);
$loop = new WP_Query( $args );
if($loop->have_posts()){
while ( $loop->have_posts() ) : $loop->the_post(); global $product; echo $product->get_title();
endwhile;?>
Upvotes: 0
Reputation: 393
try this official solution
function woocommerce_template_loop_product_title() {
echo '<h2 class="woocommerce-loop-product__title">' . get_the_title() . '</h2>';
}
Upvotes: 0
Reputation: 1
Here is what I use for my product page markups.
<script type="application/ld+json">{
"@context": "http://schema.org/",
"@type": "Product",
"name": "<?php echo the_title(); ?>",
"category": "Designer Fashion Boutique",
"description": "Designer Clothing Store and Online Fashion Boutique",
"url": "<?php the_permalink(); ?>"},
</script>
Upvotes: 0
Reputation: 1064
You only need to echo the_title();
of the product, like any post or page. And where did you get $the_product
variable?
Upvotes: -2
Reputation: 562
It's outdated question, but if anybody is looking like me these days:
<? echo $product->post->post_title; ?>
or get full html title element:
<? echo woocommerce_template_single_title(); ?>
Works for Woocommerce 2.5+
Upvotes: 15
Reputation: 613
Please try this line
<h1>"Any Questions about "<?php echo $the_product; ?>", get in touch with us"</h1>
Note that echo
use to print the PHP variables value, and every variable in PHP have $
before its name like $the_product.
Upvotes: 1