【发布时间】:2020-08-05 19:56:56
【问题描述】:
我尝试通过 +1 检查插件 located here 稍作修改 因此,对于所有 Virtual Downloadable Free (price=0,00) 和延期交货产品,我希望 Woocommerce 将订单状态设置为“处理中”
我使用下面的代码得到的结果 - Woocommerce 设置订单状态“待付款” 是否有任何想法如何将其切换为“处理”:
add_action('woocommerce_checkout_order_processed', 'handmade_woocommerce_order');
function handmade_woocommerce_order( $order_id )
{
$order = wc_get_order($order_id);
foreach ($order->get_items() as $item_key => $item_values):
$product_id = $item_values->get_product_id(); //get product id
//get prodct settings i.e virtual
$virtual_product = get_post_meta($product_id,'_virtual',true);
$downloadable_product = get_post_meta($product_id,'_downloadable',true);
$product_backordered=backorders_allowed($product_id,'_backorders',true);
$price = get_post_meta($product_id,'_regular_price',true);
$virtuald=get_option('hmade_vd');
if($virtuald=='yes' && $downloadable_product=='yes' && $virtual_product=='yes' && $product_backordered=='yes')
{
if($price=='0.00')
{
$order->update_status( 'processing' );
}
}
endforeach;
}
【问题讨论】:
-
此钩子不适用于
$order->update_status(),请参阅:stackoverflow.com/a/45987434/11987538
标签: php wordpress woocommerce product orders