相关疑难解决方法(0)

通过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万
查看次数

如何扩展 woocommerce api 端点?

我正在尝试扩展 woocommerce api 中的客户端点,以包含我在 Functions.php 中创建的一些自定义字段。但我不明白该怎么做。

我已将class-wc-rest-customers-controller.phpwoocommerce 插件 (woocommerce/includes/api/) 复制到主题中的 woocommerce 文件夹中,就像您在想要编辑 woocommerce 文件时应该对它们执行的操作一样。

这就是我的 class-wc-rest-customers-controller.php 的样子: https://www.pastebucket.com/561405

我现在的计划是编辑该文件的副本以包含我在functions.php 中添加的custom_fields。但这部分我无法解决。

这是我的functions.php中的代码,我添加了自定义字段: https: //www.pastebucket.com/561406

感觉就像是在 class-wc-rest-customers-controller.php 中第 475 行的函数中,但我不确定。所以我想知道应该在哪里以及如何添加自定义字段class-wc-rest-customers-controller.php,或者我对此全错了?

php wordpress woocommerce woocommerce-rest-api

5
推荐指数
2
解决办法
2924
查看次数