【问题标题】:Set Price and Min Order quantity in WooCommerce在 WooCommerce 中设置价格和最小订单数量
【发布时间】:2020-12-02 01:18:15
【问题描述】:

我刚刚为我的客户完成了一个自定义主题。但是他想为这些产品设置 0.50eur 的价格和最低订购价格here

我遇到的问题是所有产品都是使用 WP All Import Pro 从一个永久站点导入的。我有 2 个 Feed 正在运行,1 个每天 4 次引入产品,一个每小时更新价格。

显然,我需要将某种过滤器添加到我的 functions.php 文件中,但我不知道从哪里开始。非常感谢您的帮助。

【问题讨论】:

  • 对不起,我无法得到你想要达到的目标。您是否要连接到 wp all import?或者您的提要使用一些外部插件/脚本运行,这些插件/脚本负责更新您网站上的内容?我想我们需要更多信息来为您指明正确的方向,有很多可能性,但您需要更清楚自己的目标
  • 嗨 Diego,所以基本上 wp all import 每天 4 次在一个提要中引入多个产品、图像、图块和 woocommerce 类别。我有另一个提要,它每小时导入和更新这些产品的价格。我的客户想要的是将 1 个特定产品类别下的所有产品的价格设置为 0.50 欧元,并将最小订单设置为 500 件。希望这是有道理的?

标签: php wordpress woocommerce wordpress-hook wpallimport


【解决方案1】:

根据你的 cmets,我想你需要先看看这个 from Wp All Import documentation

之后你可以看到你有多个钩子,其中一个是 pmxi_saved_post,继续下面的例子你可以做这样的事情:

function fix_price_after_import( $post_id, $xml_node, $is_update ) {
    if ( ! empty( $post_id ) ) {
        $current_prod = wc_get_product( $post_id );
        if ( ! empty( $current_prod ) && $current_prod instanceof WC_Product ) {
            $categories_to_update = array(100,200); // product_cat IDS
            if (!empty(array_intersect($categories_to_update,$current_prod->get_category_ids()))){
                // Current prod has at least one of the categories you have to update
                $current_prod->set_price(0.5);  
                $current_prod->save();
            }
        }
    }
    
}

add_action( 'pmxi_saved_post', 'fix_price_after_import', 10, 3 );

我没有测试代码,但它应该给你一个起点

【讨论】:

  • 感谢 Diego,已将其添加到我的 functions.php 文件中,但目前还没有更新。
  • 你有什么办法调试它吗?如果该代码曾经运行过?你有分期吗?如果是这样,也许您可​​以从该示例中逐步删除“ifs”,看看是否有任何工作/代码是否完全执行
猜你喜欢
  • 1970-01-01
  • 2017-04-04
  • 1970-01-01
  • 2019-07-08
  • 2018-12-24
  • 1970-01-01
  • 2013-10-16
  • 2019-07-29
  • 2016-11-01
相关资源
最近更新 更多