douque9982 2018-10-24 20:16
浏览 106

Woocommerce设定新的订单状态

I have digital and physical products on my store. I would like to have a separate email when an order is placed where a digital product was ordered and not use the email where the order status is completed.

The workaround I thought of is to create a custom status and then create a new email for that status.

I have successfully created the order status my issue is with setting the status when the order comes in. This is my code:

add_action( 'woocommerce_thankyou', 'change_order_status', 10, 1 );
function change_order_status( $order_id){

$order = wc_get_order( $order_id );
foreach ( $order->get_items() as $item_id => $item_values ) {

// Product_id
$product_id = $item_values->get_product_id(); 

// OR the Product id from the item data
$item_data = $item_values->get_data();
$product_id = $item_data['product_id'];

# Targeting a defined product ID
if ( $product_id == 437 ) {
$order->update_status('digital-completed');
}   


}
}

With this code the order is first set to "Completed" and then it gets updated to my custom status. This means that the buyer will receive two emails, one for the completed status and one for my custom status.

I'm struggling to find a way to set the order to my custom status when it's first placed.

Is there a better to do this?

Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 易康econgnition精度验证
    • ¥15 线程问题判断多次进入
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致