title: How to modify the woocommerce price via functions.php?
body: <p>I'm doing an eCommerce with woocommerce and I must do the following:</p>
  
  <p>Modify the price of all products through functions.php. The function I created works for all of the site's prices, except for the values of the cart.</p>
  
  <p>I'm putting the function below:</p>
  
  <pre><code>function woo_change_price($price, $product) {
  global $woocommerce, $product;
  $post_id = $product-&gt;id;
  
  
  $regular_price = get_post_meta( $post_id, '_regular_price', true);
  $sale_price = get_post_meta( $post_id, '_sale_price', true);
  $cupom_value = ($regular_price - $sale_price) / 10;
  $price = $cupom_value;
  
  return $price;
  </code></pre>
  
  <p>}</p>
  
  <pre><code>add_filter('woocommerce_get_price', 'woo_change_price', 99);
  add_filter('woocommerce_get_sale_price', 'woo_change_price', 99);
  add_filter('woocommerce_order_amount_item_subtotal', 'woo_change_price', 99);
  </code></pre>
  
  <p>See that what I need is to get the regular price and the price on sale of the product and make a basic account of mathematics, subtracting the two and dividing by 10. The result I set as the new price of the product.</p>
  
  <p>This function works perfectly in all site, except in the cart. When I see the cart, all the values are set to 0 (the prices, the total, the subtotals etc).</p>
  
  <p>I found why it is happening this error, but I don't now how to fix it. The problem is: the <em>$product->id</em> is not identified by the cart and then returns 0.</p>
  
  <p>How can I fix that?</p>
  
  <p>Thank you!</p>