Istiaq Nirab full stack + ai
← Writing
WooCommerce Sep 25, 2022

WooCommerce change price programmatically

Change WooCommerce product price ( simple & variable )

To change existing product price on WooCommerce via programmatically , You need to use these filter Hooks :

<?php

add_filter( 'woocommerce_product_get_regular_price', 'custom_dynamic_regular_price', 10, 2 );
add_filter( 'woocommerce_product_get_price', 'custom_dynamic_sale_price', 10, 2 );
add_filter( 'woocommerce_product_variation_get_price', 'custom_dynamic_sale_price', 10, 2 );

Simple Product

If product type is simple or it’s based on WC_Product_Simple class , You might be use these simple product related filter hooks only :

<?php

add_filter( 'woocommerce_product_get_regular_price', 'function_for_logic', 10, 2 );
add_filter( 'woocommerce_product_get_price', 'function_for_logic', 10, 2 );

EXAMPLE :

update regular price

<?php

add_filter('woocommerce_product_get_regular_price', 'update_regular_price', 10, 2);

function update_regular_price($regular_price, $product) {
   // some logic happen here

   return $regular_price;
}

update sale price

<?php

add_filter('woocommerce_product_get_price', 'update_sale_price', 10, 2);

function update_sale_price($price, $product) {
   // some logic happen here

   return $price;
}

Variable Product

To update variation price you need to use these hooks :

<?php

add_filter( 'woocommerce_product_variation_get_price', 'custom_dynamic_sale_price', 10, 2 );
add_filter( 'woocommerce_variation_prices_price', 'custom_dynamic_sale_price', 10, 2 );
add_filter( 'woocommerce_variation_prices_sale_price', 'custom_dynamic_sale_price', 10, 2 );

EXAMPLE :

update variation price

<?php

add_filter('woocommerce_product_variation_get_price', 'update_variation_price', 10, 2);

function update_variation_price($price, $variation) {
  // some logic happen here

  return $price;
}

Thanks.

Discussion

Comments run on giscus, backed by GitHub Discussions — sign in with GitHub to reply.

More posts
LLM

Five steps from a business problem to an LLM that actually ships

Understand, prepare, select, customize, productionize. A working order of operations for picking a language model and getting it into production without burning a quarter.

2026-09-12
NLP

N-grams: the language model before language models

How N-grams turn text into countable sequences, how they predict the next word, and why counting eventually stopped being enough.

2026-09-11
Laravel

Setup vsCode for Laravel Development

The extensions and keyboard shortcuts that turn Visual Studio Code into a proper Laravel editor.

2023-09-22
ContactGMT+6

Have something that needs building, fixing, or finishing? Write one paragraph — that's usually enough.

open to new work
Local time--:--:--
Based inDhaka, BD
Experience6+ years