With this code, you can enter the price in the basket from an arbitrary field. But as soon as you set the format for displaying the price on the screen in the else container ( and only for simple goods ), the basket counts and sums up only the first digit of numbers (that is, thousands).

If the format in the else container does not specify the price, everything works like a clock, except that the screen displays an unformatted number instead of the normal price (only for a simple product !!!) . Variable goods can be formatted and displayed as you wish. Why? Is it possible not to override the price for display on the screen?

 add_filter('woocommerce_get_price_html', 'sv_change_product_html', 10, 2 ); function sv_change_product_html( $price_html, $product ) { $rrp = get_post_meta( $product->id, 'rrp_price', true ); if ( ! empty( $rrp ) ) { $price_html = '<span class="amount">' . wc_price( $rrp ) .'</span>'; if($product->product_type=='variable') { $nrrp = number_format($rrp, 0, ',', ' '); $nrrp = 'от '. $nrrp; //$nrrp .= ' грн.'; return $nrrp; } else { $nrrp = number_format($rrp, 0, ',', ' '); $nrrp .= ' грн.'; return $nrrp; } return $rrp; } } function sv_change_product_price_cart( $price, $cart_item, $cart_item_key ) { $rrp = get_post_meta( $cart_item['product_id'], 'rrp_price', true ); if ( ! empty( $rrp ) ) { $price = wc_price( $rrp ); var_dump($price); } return $price; } add_filter( 'woocommerce_cart_item_price', 'sv_change_product_price_cart', 10, 3 ); 
  • >> the basket counts and sums up only the first digit of numbers (ie, thousands) << I looked through the code, used the search, but could not find a single sign / operator of mathematical addition. What amounts are we talking about? Where are they? - test123
  • in the class-wc-cart.php template , the price goes there, and since the formatted number (with the thousands separator) is considered to be in $ nrrp, only the first digit is considered user271244
  • Why then do you give the working code, and you are silent about the code that does not work? IMHO, you should have shown a code that incorrectly thinks to be prompted to you how to make this count correct. Now for your question, I can only suggest - to remove the formatting, because the source of the calculator for us is the black box. - test123
  • In such a case, the unformatted price of the goods will be displayed on the screen (in the store), is it possible to display the formatted price separately? - user271244
  • So who's stopping? Format the counted data and output. Formatting is an operation that is performed directly before rendering. It is logical that it is not needed at the calculation stage. If you do not have access to a calculator, that is another question. - test123

0