产品标题旁边的价格 [woocommerce]

我有这个功能,我想在产品价格旁边添加。我用过get_price_html()和$price = $product->get_price_html


function woocommerce_template_loop_product_title() {

echo '<h4 class="woocommerce-loop-product__title">' . get_the_title() . '</h4>'; }

电流输出

http://img3.mukewang.com/643a655b0001aab403840321.jpg

期望的输出

http://img4.mukewang.com/643a65650001d8b403540334.jpg


慕盖茨4494581
浏览 112回答 3
3回答

蓝山帝景

function woocommerce_template_loop_product_title() {global $product;$price = $product->get_price_html();echo '<h4 class="woocommerce-loop-product__title h-price">' . get_the_title() .'&nbsp'. $price .'</h4>';}我的答案。

慕尼黑5688855

您需要添加一个操作来更改标题。所以我为您编写了这段代码,只需将其添加到您的 functions.phpadd_action( 'the_title', 'add_price_title' );function add_price_title($title) {&nbsp;$post_ID = get_the_ID();&nbsp;$the_post = get_post($post_ID);&nbsp;$date = $the_post->post_date;&nbsp;$maintitle = $the_post->post_title;&nbsp;$count='';&nbsp;$product = wc_get_product( $post_ID );&nbsp;$price = $product->get_price();if ($the_post->post_status == 'publish' AND $the_post->post_type == 'product' AND in_the_loop()) {&nbsp;&nbsp;return "<span type='number' class='notbold'>".$title." $".$price.""."</span>";}else{&nbsp;return $title;&nbsp; &nbsp;}}

萧十郎

// define the woocommerce_shop_loop_item_title callback&nbsp;function action_woocommerce_shop_loop_item_title() {&nbsp;&nbsp; &nbsp; // make action magic happen here...&nbsp;&nbsp; &nbsp; global $product;&nbsp; &nbsp; echo '<p>'.get_post_meta($product->get_id(), '_price', true).'</p>';};&nbsp;// add the action&nbsp;add_action( 'woocommerce_shop_loop_item_title', 'action_woocommerce_shop_loop_item_title', 10 );&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP