php 在 woo commerce 中回显产品名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17212727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:29:59  来源:igfitidea点击:

Echo product title in woo commerce

phpwordpresswoocommerce

提问by Adam Scot

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?

然而,这似乎不起作用,我如何在 Woocommerce 中提取产品名称?

回答by Tomas Chudjak

It's outdated question, but if anybody is looking like me these days:

这是过时的问题,但如果有人现在看起来像我:

<? echo $product->post->post_title; ?>

or get full html title element:

或获取完整的 html 标题元素:

<? echo woocommerce_template_single_title(); ?>

Works for Woocommerce 2.5+

适用于 Woocommerce 2.5+

回答by Jahanzeb

Please try this line

请试试这条线

<h1>"Any Questions about "<?php echo $the_product; ?>", get in touch with us"</h1>

Note that echouse to print the PHP variables value, and every variable in PHP have $before its name like $the_product.

请注意,echo用于打印 PHP 变量值,并且 PHP 中的每个变量都$在其名称之前,例如 $the_product。

回答by Richard Russ

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>

回答by Chintan Mathukiya

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

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

回答by Gurpreet Singh

<?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;?>

回答by rgdesign

You only need to echo the_title();of the product, like any post or page. And where did you get $the_productvariable?

您只需要了解echo the_title();产品,就像任何帖子或页面一样。你从哪里得到$the_product变量?