英文:
How to add text between price and short description in WordPress (WooCommerce)?
问题
以下是您要翻译的部分:
"I have next problem. I need to add text after price of the product and before short description. This text can be added in short description on first line like an option. The text that I want to add show the same price without 3% of itself.
I put this code in function.php of my current theme:
add_action('woocommerce_short_description','wire_price_3',11);
function wire_price_3()
{
$product = wc_get_product();
$product_price = $product->get_regular_price();
$percent_3 = ($price_p *3)/100;
$percet_price = $product_price - $percent_3;
echo "<h1>Wire price: {$percet_price}</h1>";
echo "\n";
}
Eveythring works well but when I add this code my checkout page become a mess and show some code.
So, my question is how to find solution to this problem? BTW how can I make to show your text this text for example in green color.
Thank you."
英文:
I have next problem. I need to add text after price of the product and before short description. This text can be added in short description on first line like an option. The text that I want to add show the same price without 3% of itself.
I put this code in function.php of my current theme:
add_action('woocommerce_short_description','wire_price_3',11);
function wire_price_3()
{
$product = wc_get_product();
$product_price = $product->get_regular_price();
$percent_3 = ($price_p *3)/100;
$percet_price = $product_price - $percent_3;
echo "<h1>Wire price: {$percet_price}</h1>";
echo "\n";
}
Eveythring works well but when I add this code my checkout page become a mess and show some code.
So, my question is how to find solution to this problem? BTW how can I make to show your text this text for example in green color.
Thank you.
答案1
得分: 1
我已经修改了你的代码,请尝试检查它是否正常工作
add_action( 'woocommerce_single_product_summary', 'mx_price_per_installments_w_fee', 30 );
function mx_price_per_installments_w_fee() {
global $product;
$price = (float) $product->get_price();
$feeextended = (3/100) * $price;
$price4extendedinstallments = $price - $feeextended;
echo "
<div id='installments-container'>
<div id='installments-text'>
<div class='bold'>Wire price: <span class='success'>". number_format($price4extendedinstallments, 2, ",", ".") ." €.</span></div>
</div>
</div>
";
}
英文:
i have changed your code, please try if it works properly
add_action( 'woocommerce_single_product_summary', 'mx_price_per_installments_w_fee', 30 );
function mx_price_per_installments_w_fee() {
global $product;
$price = (float) $product->get_price();
$feeextended = (3/100) * $price;
$price4extendedinstallments = $price - $feeextended;
echo "
<div id='installments-container'>
<div id='installments-text'>
<div class='bold'>Wire price: <span class='success'>". number_format($price4extendedinstallments, 2, ",", ".") ." €.</span></div>
</div>
</div>
";
}
答案2
得分: 0
尝试这个代码:
add_action('woocommerce_after_add_to_cart_form', 'mx_price_per_installments_w_fee', 30);
function mx_price_per_installments_w_fee() {
global $product;
$price = (float) $product->get_price();
$feeextended = (3/100) * $price;
$price4extendedinstallments = $price - $feeextended;
echo "
<div id='installments-container'>
<div id='installments-text'>
<div class='bold'>Wire price: <span class='success'>" . number_format($price4extendedinstallments, 2, ",", ".") . " €.</span></div>
</div>
</div>
";
}
英文:
try this
add_action( 'woocommerce_after_add_to_cart_form', 'mx_price_per_installments_w_fee', 30 );
function mx_price_per_installments_w_fee() {
global $product;
$price = (float) $product->get_price();
$feeextended = (3/100) * $price;
$price4extendedinstallments = $price - $feeextended;
echo "
<div id='installments-container'>
<div id='installments-text'>
<div class='bold'>Wire price: <span class='success'>". number_format($price4extendedinstallments, 2, ",", ".") ." €.</span></div>
</div>
</div>
";
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论