Want to filter the regular price of woocommerce products.

Based on product id and their meta data I want filter the get_regular_price of that product

Something like this.

function filter_woocommerce_get_regular_price( $array, $int, $int ) { 

    return $array; 

add_filter( 'woocommerce_get_regular_price', 'filter_woocommerce_get_regular_price', 10, 3 ); 
  • you have 3 filters for that woocommerce_product_get_price, woocommerce_product_get_sale_price and woocommerce_product_get_regular_price, each have ($price, $product) as arguments – mmm Oct 11 '17 at 9:21

Unfortunately the filter hook "woocommerce_get_regular_price" is not usable any more. There is another one alternative of that, you can use this below code to achieve your need.

function filter_woocommerce_get_regular_price( $price, $product ) { 

    // use $product->get_id() to get product ID
    // Do any custom logical action

    return $price; 
add_filter( 'woocommerce_product_get_regular_price', 'filter_woocommerce_get_regular_price', 10, 2 );
  • Will this work if I am getting the regular price like this $prod_price = get_post_meta( get_the_ID(), '_regular_price', true); – Mojo Jojo Oct 12 '17 at 6:30
  • Price is on the argument, Just use $price to take it inside the function – Jaed Mosharraf Oct 12 '17 at 6:32
  • No , you did not get my point. Will your filter work for this as well $prod_price = get_post_meta( get_the_ID(), '_regular_price', true); . It won't obviously because because its filter for get_regular_price function right ? – Mojo Jojo Oct 12 '17 at 7:03
  • Yes, when you use get_post_meta() it will avoid all filters – Jaed Mosharraf Oct 12 '17 at 7:24
  • Ohk so I have change all the get_post meta to get_regular_price . Thanks – Mojo Jojo Oct 12 '17 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.