在WooCommerce中设置价格和最小订单数量

问题描述

我几乎为我的客户完成了一个自定义主题。但是,他想将这些产品here

的价格和最低订购价设置为0.50eur

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

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

解决方法

根据您的评论,我想您需要先看看第一个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 );

我没有测试代码,但是它应该为您提供一个起点