Good day to all.
It is necessary to make a calculator for the goods, on each page, for this you need to insert the price of the goods, on the page of which we are, into the input.
Wrote such an input

<input type="text" id="price" value="" disabled> 

But that insert into value - no idea.
Google issued this:

 $product->get_price_html() ; 

BUT, when I insert, the page breaks.
Also, I decided to withdraw $ product

 var_dump($product); 

Out

string (7) "classic"

that is, the product has only a name, although it indicated both the price and the image in the admin area
It is also necessary to clarify that removed the price display on the product page.
Thank you in advance for the answers and sorry for such a crooked explanation)

  • one
    What file do you paste it into? Obviously not there. $ product is a global variable, an object containing all the characteristics of a product. At you this variable is interrupted by any line. Therefore, an attempt to insert the correct code from Google destroys the page - the string does not and cannot have the get_price_html () method. Show your file in general. - KAGG Design
  • @KAGGDesign Thanks for the answer. I already figured out, I just did not declare the variable in this file. I put in the themes / betheme (theme name) /woocommerce/content-product.php file. Here is a link to the code ( pastebin.com/7Eu6dZeM 163 line) But here he does not insert the value into the input, but inserts "₽2,150.00" disabled> "I will be grateful if you help with my problem. - tweeker
  • @KAGGDesign I need to make a simple calculator. Which would calculate the PRODUCT PRICE * NUM, so I created 2 imput and would like the price to always show the first product, on the page of which we are, and already work with it - tweeker
  • one
    Well, you have the price and - 2150 rubles. - KAGG Design
  • @KAGGDesign is not, I mean, the fact that it inserts the html tag, and not in the input value, here is the screen imgur.com/a/EAQiM - tweeker

2 answers 2

I used <?php echo $product->get_price_html(); ?> <?php echo $product->get_price_html(); ?> to display the price of the goods. get_ only gets the value, you just need to display it.

    get_price_html() is your method that applies to the $product entity. Together, it returns the value for your input . I don't see the form itself, but the input will be in some sort of div. Here is an example of what should work:
    In the view itself (html) -

    <div id='my_input'></div>

    In php:

     woocommerce_form_field( 'my_input', array( 'type' => 'text', 'class' => array('my-field-class form-row-wide'), 'label' => __('My input') . '</br>', 'placeholder' => __('0.00'), 'value' => $product->get_price_html() ) ); 
    • Thank you for the answer, as I understand it, you can simply insert into value = "<? = $ Product-> get_price_html ();?>", But the catch is that there is nothing in $ product except the name, that is, there is no place to take the price . - tweeker
    • I used your method - it also does not work, I wrote the reason in the past comments. - tweeker
    • one
      I'm sorry, my stupidity, I don't know why I thought so, the variable is in php, I will correct the answer now - Ruslan Dragan
    • there is no form, there is simply an imput and a label. Why not simply in value = "<? = $ product-> get_price_html ();?>" to substitute? - tweeker
    • It is also not entirely clear where to get the php code, I thought to make everything into the / woocomerce-content-single-product.php theme folder. I hope for your answer. - tweeker