Replies: 1
Hello,
EDIT : Please ignore what is below, it doesn’t seem to be the proper log, I’m currently investigating to find where the log is generated so I can give a proper explanation, please ignore this topic for now. Sorry.
A few weeks ago I implemented a custom plugin to remove specific tags on a product when the stock reached 0.
function action_woocommerce_no_stock( $wc_get_product ) {
$tag_ids = $wc_get_product->get_tag_ids();
$del_tags = array(28, 30);
$updated_tags = array_filter($tag_ids, function($tag) use ($del_tags) {
return (!in_array($tag, $del_tags));
});
$wc_get_product->set_tag_ids( $updated_tags );
$wc_get_product->save();
}
add_action( 'woocommerce_no_stock', 'action_woocommerce_no_stock', 10, 1 );
I’m not sure to understand why it happens but I guess it’s related to the woocommerce_no_stock action.
This is the log in woocommerce status:
`2022-01-17T13:32:56+00:00 CRITICAL Uncaught Error: Call to undefined function delete_tags() in /home/private/website.com/wp-content/plugins/delete-tag-on-out-of-stock-products/plugin.php:35
Stack trace:
#0 /home/private/website.com/wp-includes/class-wp-hook.php(303): action_woocommerce_no_stock(Object(WC_Product_Simple))
#1 /home/private/website.com/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(”, Array)
#2 /home/private/website.com/wp-includes/plugin.php(470): WP_Hook->do_action(Array)
#3 /home/private/website.com/wp-content/plugins/woocommerce/includes/wc-stock-functions.php(231): do_action(‘woocommerce_no_…’, Object(WC_Product_Simple))
#4 /home/private/website.com/wp-content/plugins/woocommerce/includes/wc-stock-functions.php(207): wc_trigger_stock_change_notifications(Object(Automattic\WooCommerce\Admin\Overrides\Order), Array)
#5 /home/private/website.com/wp-content/plugins/woocommerce/includes/wc-stock-functions.php(107): wc_reduce_stock_levels(452)
#6 /home/private/website.com/wp-i in /home/private/website.com/wp-content/plugins/delete-tag-on-out-of-stock-products/plugin.php at line 35`
Is there a way to adapt my function so it doesn’t trigger a fatal error on order status update ? (It happened when canceling some orders).
Best regards,
Oshika