admin管理员组文章数量:1320661
I'm building a plugin that needs to update data after order creation! I have succeeded in doing that on the website but not in the REST API
What I have done is using woocommerce_thankyou
that working fine after checkout through the website but not the REST API too!!
So how to do the same function below after Creating an Order through WooCommerce REST API!!
add_action('woocommerce_thankyou', 'edit_stock_metadata', 10, 1);
function edit_stock_metadata($order_id)
{
if (!$order_id)
return;
// Getting an instance of the order object
$order = wc_get_order($order_id);
// iterating through each order items (getting product ID and the product object)
// (work for simple and variable products)
foreach ($order->get_items() as $item_id => $item) {
if ($item['variation_id'] > 0) {
$product_id = $item['variation_id']; // variable product
$variation = new WC_Product_Variation($product_id);
$stock_qty = intval($variation->get_meta('_stock_multiplier'));
$item_quantity = $item->get_quantity(); // Get the item quantity
$variation->update_meta_data('_stock_multiplier', ($stock_qty - $item_quantity));
$variation->save();
}
}
}
本文标签: phpWoocommerce hook run after an Order been created through REST API
版权声明:本文标题:php - Woocommerce hook run after an Order been created through REST API 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742065710a2418821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论