A Complete explanation of WordPress action and filter hooks.
xxxxxxxxxx
add_filter('woocommerce_get_product_price', 'apply_discount', 100, 2);
function apply_discount($price, $product ){
if( $price > 100 ) {
$price = $price - ($price * 0.2);
}
return $price;
}
xxxxxxxxxx
function add_filter($name, $callback) {
global $filters;
$filters[$name][] = $callback;
}
function apply_filters($name, $value) {
global $filters;
if(array_key_exists($name, $filters)) {
foreach($filters[$name] as $callback) {
$value = $callback($value);
}
}
return $value;
}