好吧,如果有人在寻找这个问题的答案,我会在多睡一会儿后找到答案。我必须去掉返回和第二个函数。现在代码如下所示
add_action( \'woocommerce_single_product_summary\', \'my_units_sold_counts\', 19 );
function my_units_sold_counts($units_sold) {
global $product;
$units_sold = get_post_meta( $product->id, \'total_sales\', true );
if ($units_sold <= 2 ) {
echo \'<p style="font-size: 1.1em; font-weight: 900; color: #908c8c;">No units sold yet. Be the first and use coupon code: xyz</p>\';
} else {
echo \'<p style="font-size: 1.1em; font-weight: 900; color: #908c8c;">\' . \'<i style="margin-right: 10px;"class="fa fa-line-chart"></i>\' . sprintf( __( \'Units Sold: %s\', \'woocommerce\' ), $units_sold ) . \'</p>\';
}
}