在WordPress(WooCommerce)中如何在价格和简短描述之间添加文本?

huangapple go评论60阅读模式
英文:

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(&#39;woocommerce_short_description&#39;,&#39;wire_price_3&#39;,11);
   function wire_price_3()
   {
        $product = wc_get_product();
	$product_price = $product-&gt;get_regular_price();
        $percent_3 = ($price_p *3)/100;
        $percet_price = $product_price - $percent_3;
	echo &quot;&lt;h1&gt;Wire price: {$percet_price}&lt;/h1&gt;&quot;;
	echo &quot;\n&quot;;
   }

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( &#39;woocommerce_single_product_summary&#39;, &#39;mx_price_per_installments_w_fee&#39;, 30 );
function mx_price_per_installments_w_fee() {
    global $product;
	$price = (float) $product-&gt;get_price();
    $feeextended = (3/100) * $price;
    $price4extendedinstallments = $price - $feeextended;
   echo &quot;
   &lt;div id=&#39;installments-container&#39;&gt;
       &lt;div id=&#39;installments-text&#39;&gt;
		&lt;div class=&#39;bold&#39;&gt;Wire price: &lt;span class=&#39;success&#39;&gt;&quot;. number_format($price4extendedinstallments, 2, &quot;,&quot;, &quot;.&quot;) .&quot; €.&lt;/span&gt;&lt;/div&gt;
       &lt;/div&gt;
   &lt;/div&gt;
   &quot;;
}

答案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( &#39;woocommerce_after_add_to_cart_form&#39;, &#39;mx_price_per_installments_w_fee&#39;, 30  );
function mx_price_per_installments_w_fee() {
    global $product;
    $price = (float) $product-&gt;get_price();
    $feeextended = (3/100) * $price;
    $price4extendedinstallments = $price - $feeextended;
   echo &quot;
   &lt;div id=&#39;installments-container&#39;&gt;
       &lt;div id=&#39;installments-text&#39;&gt;
        &lt;div class=&#39;bold&#39;&gt;Wire price: &lt;span class=&#39;success&#39;&gt;&quot;. number_format($price4extendedinstallments, 2, &quot;,&quot;, &quot;.&quot;) .&quot; €.&lt;/span&gt;&lt;/div&gt;
       &lt;/div&gt;
   &lt;/div&gt;
   &quot;;
}

huangapple
  • 本文由 发表于 2023年2月10日 05:44:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定