Update 4 (September 2019)
- 2 ( Woocommerce 3.3.x)
- Woocommerce 3 ( ):
woocommerce_get_variation_prices_hash , wc_delete_product_transients()… - (. ).
1) :
WooCommerce 3+
, , :
add_filter('woocommerce_product_get_price', array( $this, 'custom_price' ), 99, 2 );
add_filter('woocommerce_product_get_regular_price', array( $this, 'custom_price' ), 99, 2 );
add_filter('woocommerce_product_variation_get_regular_price', array( $this, 'custom_price' ), 99, 2 );
add_filter('woocommerce_product_variation_get_price', array( $this, 'custom_price' ), 99, 2 );
add_filter('woocommerce_variation_prices_price', array( $this, 'custom_variable_price' ), 99, 3 );
add_filter('woocommerce_variation_prices_regular_price', array( $this, 'custom_variable_price' ), 99, 3 );
add_filter( 'woocommerce_get_variation_prices_hash', array( $this, 'add_price_multiplier_to_variation_prices_hash' ), 99, 1 );
public function get_price_multiplier() {
return 2;
}
public function custom_price( $price, $product ) {
return $price * get_price_multiplier();
}
public function custom_variable_price( $price, $variation, $product ) {
return $price * get_price_multiplier();
}
public function add_price_multiplier_to_variation_prices_hash( $hash ) {
$hash[] = get_price_multiplier();
return $hash;
}
() WooCommerce 3+.
2) : functions.php ( ):
function get_price_multiplier() {
return 2;
}
add_filter('woocommerce_product_get_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_get_regular_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'custom_price', 99, 2 );
function custom_price( $price, $product ) {
return $price * get_price_multiplier();
}
add_filter('woocommerce_variation_prices_price', 'custom_variable_price', 99, 3 );
add_filter('woocommerce_variation_prices_regular_price', 'custom_variable_price', 99, 3 );
function custom_variable_price( $price, $variation, $product ) {
return $price * get_price_multiplier();
}
add_filter( 'woocommerce_get_variation_prices_hash', 'add_price_multiplier_to_variation_prices_hash', 99, 1 );
function add_price_multiplier_to_variation_prices_hash( $hash ) {
$hash[] = get_price_multiplier();
return $hash;
}
woocommerce 3+
:
woocommerce_product_get_sale_price (, )woocommerce_variation_prices_sale_price ( (-))woocommerce_product_variation_get_sale_price ( )
woocommerce 3:
, :
woocommerce_variation_prices_pricewoocommerce_variation_prices_regular_pricewoocommerce_variation_prices_sale_price
Woocommerce 3, woocommerce_get_variation_prices_hash , , .
, ( , )
.: - get_variation_prices
( ) :
woocommerce_price_filter_widget_min_amount $pricewoocommerce_price_filter_widget_max_amount $price