下单后缺货时自动为产品添加特定类别和标签 [英] Automatically add a specific category and tags to a product when it goes out of stock after the order is placed

查看:73
本文介绍了下单后缺货时自动为产品添加特定类别和标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个关于 wordpress 和 WooCommerce 的问题

Hi I'm facing an issue regarding wordpress and WooCommerce

我想自动化这个过程当产品缺货时,它会自动添加到其他特定类别,并为其分配一个‘缺货’标签"

喜欢这些附加的图片:

  • 产品缺货时

  • 产品已自动添加到指定类别

  • 我可以在这个类别的小部件中显示这一点

  • 最后还有一个标签分配给它

我只需要在编辑页面中应用分类法

I just need the taxonomy to be applied in the edit page

每次产品缺货时,我都会手动执行此过程

I do this manual process every time when the product run out of stock

  1. 我转到产品编辑页面 -> 将其添加到名为缺货"的产品类别
  2. 然后为其分配一个标签缺货"

我想自动化.我尝试了所有解决方案但都失败了,即使我尝试了很多插件

I want to automate that. I tried every solution but failed, even I tried many plugins

有人可以帮助我吗,或者有任何其他方法可以从后端或通过向 wordpress 添加任何自定义函数来执行此操作?

Can someone help me or there is any other way of doing this from the backend or by adding any custom function to wordpress?

推荐答案

股票变动事件后可用的钩子,触发电子邮件和添加订单备注位于

The available hooks after stock change events, triggers emails and adds order notes are located in

https://github.com/woocommerce/woocommerce/blob/master/includes/wc-stock-functions.php

我们在哪里找到包含一些动作钩子的函数 wc_trigger_stock_change_notifications()

Where we find the function wc_trigger_stock_change_notifications() which contains some action hooks


可用的钩子:


Available hooks:

// No stock
function action_woocommerce_no_stock( $wc_get_product ) {
    // make action magic happen here... 
}
add_action( 'woocommerce_no_stock', 'action_woocommerce_no_stock', 10, 1 );

// Low stock
function action_woocommerce_low_stock( $wc_get_product ) { 
    // make action magic happen here... 
}
add_action( 'woocommerce_low_stock', 'action_woocommerce_low_stock', 10, 1 );

// On backorder
function action_woocommerce_product_on_backorder( $array ) { 
    // make action magic happen here... 
}
add_action( 'woocommerce_product_on_backorder', 'action_woocommerce_product_on_backorder', 10, 1 );


所以对于你想要的,你可以使用 woocommerce_no_stock3.0 中的 CRUD 对象

function action_woocommerce_no_stock( $wc_get_product ) {
    // Set category ids
    $wc_get_product->set_category_ids( array( 39, 2 ) );

    // Product set tag ids
    $wc_get_product->set_tag_ids( array( 40 ) );

    // Save
    $wc_get_product->save();
}
add_action( 'woocommerce_no_stock', 'action_woocommerce_no_stock', 10, 1 ); 

这篇关于下单后缺货时自动为产品添加特定类别和标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆