我具有此功能,我想在产品价格旁边添加。
我使用了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>'; }
当前输出
所需的输出
答案 0 :(得分:1)
您需要添加一个操作来更改标题。所以我为您编写了这段代码,只需将其添加到您的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;
}
}
答案 1 :(得分:1)
class Scores:
students =[]
def __init__(self, code, listScore=[]):
self.Score = listScore
self.code=code
Scores.students.append(self)
def add_Score(self):
for i in range(3):
d = input(f"Enter number {i+1} : ")
self.Score.append(d)
def pass__(self):
for grade in self.Score:
if int(grade) < 10:
return False
return True
def Passed(self):
for student in Scores.students:
if self.pass__():
return (f" Passed : {self.code}")
答案 2 :(得分:1)
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() .' '. $price .'</h4>';}
我的答案。