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
Databases

ACID in practice: what SQLite, Postgres, MySQL and MariaDB actually promise

Atomicity, consistency, isolation and durability, one letter at a time, and how differently SQLite, Postgres, MySQL, MariaDB and a few others implement each one. Same words, different guarantees.

2026-10-01
Networking

TCP: how a connection actually works

What TCP does on top of IP: ports, the three-way handshake, sequence numbers, ACKs, retransmission, closing a connection, and the costs that pushed HTTP/3 onto QUIC.

2026-09-26
NLP

Vectorizing text: from word counts to meaning

How text becomes numbers a model can work with: one-hot vectors, bag of words, TF-IDF, the hashing trick, word embeddings and sentence embeddings, and when to use each.

2026-09-25
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