Adam Scot
Adam Scot

Reputation: 1409

Echo product title in woo commerce

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

Answers (7)

Adam Colton
Adam Colton

Reputation: 319

<?php the_title(); ?>   //just like this

Upvotes: 0

Gurpreet Singh
Gurpreet Singh

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

Chintan Mathukiya
Chintan Mathukiya

Reputation: 393

try this official solution

function woocommerce_template_loop_product_title() {
        echo '<h2 class="woocommerce-loop-product__title">' . get_the_title() . '</h2>';
    }

https://docs.woocommerce.com/wc-apidocs/source-function-woocommerce_template_loop_product_title.html#742-747

Upvotes: 0

Richard Russ
Richard Russ

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

rgdesign
rgdesign

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

Tomas Chudjak
Tomas Chudjak

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

Jahanzeb
Jahanzeb

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

Related Questions