title: Woocommerce wc_price filter usage
body: <p>i have doubt regarding usability of wc_price filter , When i look the code [<a href="https://docs.woocommerce.com/wc-apidocs/source-function-wc_price.html#489]" rel="nofollow noreferrer">https://docs.woocommerce.com/wc-apidocs/source-function-wc_price.html#489]</a> i can find wc_price filter .</p>
  
  <pre><code>function wc_price( $price, $args = array() ) {
      extract( apply_filters( 'wc_price_args', wp_parse_args( $args, array(
          'ex_tax_label'       =&gt; false,
          'currency'           =&gt; '',
          'decimal_separator'  =&gt; wc_get_price_decimal_separator(),
          'thousand_separator' =&gt; wc_get_price_thousand_separator(),
          'decimals'           =&gt; wc_get_price_decimals(),
          'price_format'       =&gt; get_woocommerce_price_format(),
      ) ) ) );
  
      $negative        = $price &lt; 0;
      $price           = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) );
      $price           = apply_filters( 'formatted_woocommerce_price', number_format( $price, $decimals, $decimal_separator, $thousand_separator ), $price, $decimals, $decimal_separator, $thousand_separator );
  
      if ( apply_filters( 'woocommerce_price_trim_zeros', false ) &amp;&amp; $decimals &gt; 0 ) {
          $price = wc_trim_zeros( $price );
      }
  
      $formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, '&lt;span class="woocommerce-Price-currencySymbol"&gt;' . get_woocommerce_currency_symbol( $currency ) . '&lt;/span&gt;', $price );
      $return          = '&lt;span class="woocommerce-Price-amount amount"&gt;' . $formatted_price . '&lt;/span&gt;';
  
      if ( $ex_tax_label &amp;&amp; wc_tax_enabled() ) {
          $return .= ' &lt;small class="woocommerce-Price-taxLabel tax_label"&gt;' . WC()-&gt;countries-&gt;ex_tax_or_vat() . '&lt;/small&gt;';
      }
  
      return apply_filters( 'wc_price', $return, $price, $args );
  }
  </code></pre>
  
  <p>This means this filter is used for changing the product price . </p>
  
  <p>so now i want to double the frontend price by code . So iwrite the following function </p>
  
  <pre><code>add_filter( 'wc_price', 'double_price', 10, 3 );
  
  function double_price( $return, $price, $args){
      $price=$price*2;
      return $price;
  
  }
  </code></pre>
  
  <p>Now the price is showing in frontend without currency symbol .</p>
  
  <p>then i rewrite it like this </p>
  
  <pre><code>function double_price( $return, $price, $args){
      $price=$price*2;
      return '&lt;span class="woocommerce-Price-amount amount"&gt;&lt;span class="woocommerce-Price-currencySymbol"&gt;£&lt;/span&gt;'.$price.'&lt;/span&gt;';
  
  }
  </code></pre>
  
  <p>Now it's working .</p>
  
  <p>But i don't think this is the correct way . <strong>Can someone explain how can i use this function properly .</strong>. What is the use of <code>$args,$price,$retun</code> in this filter ? </p>
  
  <p>Also if i need to to change all product price based on category , how can i get product id inside this filter ? if i write the product id then i will write </p>
  
  <pre><code>function double_price( $return, $price, $args){
      $price=$price*2;
       if( has_term( 'shirts', 'product_cat' ,$product-&gt;ID) ) {
         $price=130;
       }
  
      return '&lt;span class="woocommerce-Price-amount amount"&gt;&lt;span class="woocommerce-Price-currencySymbol"&gt;£&lt;/span&gt;'.$price.'&lt;/span&gt;';
  
  }
  </code></pre>
  
  <blockquote>
    <p>Please note: this question have a sub question
    <a href="https://stackoverflow.com/questions/47788254/after-using-woocommerce-product-get-price-hook-the-checkout-page-price-is-incorr">After using woocommerce_product_get_price hook the checkout page price is incorrect</a></p>
  </blockquote>