亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

產品標題旁邊的價格 [woocommerce]

產品標題旁邊的價格 [woocommerce]

PHP
慕蓋茨4494581 2023-04-15 16:50:06
我有這個功能,我想在產品價格旁邊添加。我用過get_price_html()和$price = $product->get_price_htmlfunction woocommerce_template_loop_product_title() {echo '<h4 class="woocommerce-loop-product__title">' . get_the_title() . '</h4>'; }電流輸出期望的輸出
查看完整描述

3 回答

?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

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>';}

我的答案。


查看完整回答
反對 回復 2023-04-15
?
慕尼黑5688855

TA貢獻1848條經驗 獲得超2個贊

您需要添加一個操作來更改標題。所以我為您編寫了這段代碼,只需將其添加到您的 functions.php


add_action( 'the_title', 'add_price_title' );


function add_price_title($title) {

 $post_ID = get_the_ID();

 $the_post = get_post($post_ID);

 $date = $the_post->post_date;

 $maintitle = $the_post->post_title;

 $count='';

 $product = wc_get_product( $post_ID );

 $price = $product->get_price();



if ($the_post->post_status == 'publish' AND $the_post->post_type == 'product' AND in_the_loop()) { 

 return "<span type='number' class='notbold'>".$title." $".$price.""."</span>";

}


else{

 return $title;   

}

}


查看完整回答
反對 回復 2023-04-15
?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

// define the woocommerce_shop_loop_item_title callback 

function action_woocommerce_shop_loop_item_title() { 

    // make action magic happen here... 

    global $product;

    echo '<p>'.get_post_meta($product->get_id(), '_price', true).'</p>';

}; 


// add the action 

add_action( 'woocommerce_shop_loop_item_title', 'action_woocommerce_shop_loop_item_title', 10 ); 



查看完整回答
反對 回復 2023-04-15
  • 3 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號