我尝试通过+1检查插件located here进行一些修改 因此,对于所有Virtual Downloadable Free(价格= 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;
}
答案 0 :(得分:1)
注意1:改用
Google Microsoft
钩子
注释2:要了解产品是虚拟的还是可下载的,可以使用
woocommerce_thankyou
对面的以下功能$product->is_virtual();
和$product->is_downloadable();
更多信息:https://docs.woocommerce.com/wc-apidocs/class-WC_Product.html
注意3:最好不要在foreach循环中执行操作,之后再进行检查
get_post_meta();