小编Kro*_*osL的帖子

通过WooCommerce 3中的钩子改变产品价格

在WooCommerce中,我需要将所有产品价格乘以一个数字.所以我使用了以下内容(通过插件):

add_filter('woocommerce_get_regular_price', array( $this, 'my_custom_price'), 99);
add_filter('woocommerce_get_price', array( $this, 'my_custom_price'), 99);

function my_custom_price( $original_price ) {
  global $post, $woocommerce;

  //Logic for calculating the new price here
  $new_price = $original_price * 2;

  //Return the new price (this is the price that will be used everywhere in the store)
  return $new_price;
 }
Run Code Online (Sandbox Code Playgroud)

但是,这对变体产品不起作用.我试过以下钩子没有运气:

add_filter('woocommerce_get_variation_regular_price', array( $this, 'my_custom_price'), 99);
add_filter('woocommerce_get_variation_price', array( $this, 'my_custom_price'), 99);
Run Code Online (Sandbox Code Playgroud)

唯一有效的是这一个:

add_filter('woocommerce_variation_prices_price', array( $this, 'my_custom_price'), 99);
Run Code Online (Sandbox Code Playgroud)

但这只是改变了整体价格,而不是选定的变化价格.见下图,价格是BsF.200和整体价格是正确的,200 x 2 = 400,但选择时的变化价格仍显示200:

注意:我需要它实际更改,所以显示html钩子不会工作.

变动价格

有什么我想念的,或者有什么不对吗?

php wordpress product woocommerce price

14
推荐指数
1
解决办法
2万
查看次数

标签 统计

php ×1

price ×1

product ×1

woocommerce ×1

wordpress ×1