skip to Main Content

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.

2

Answers


  1. 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>
       ";
    }
    
    Login or Signup to reply.
  2. 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>
       ";
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search