如何解决Woocommerce woocommerce_new_order在客户下达新订单时不起作用,尽管通过管理面板创建订单时效果很好
我想将订单详细信息插入我的自定义表中,该自定义表是在我的插件activated.woocommerce_new_order
在客户下达新订单时不起作用时在内部生成的,尽管在管理面板中创建订单时该订单可以正常工作。
add_action( 'woocommerce_new_order','mysite_woocommerce_order',10,1 );
function mysite_woocommerce_order($order_id){
global $wpdb;
$i=1;
$table_name=$wpdb->prefix.'posts';
/*echo $order_id;
exit();*/
/* $results = $wpdb->get_results( "SELECT ID FROM $table_name WHERE post_type = 'shop_order' AND `post_status`='wc-completed' ORDER BY ID DESC",ARRAY_A );
foreach ($results as $key => $value) {
$order_id=$value['ID'];*/
$order = wc_get_order($order_id);
$order_status = $order->get_status();
$tablename=$wpdb->prefix.'seller_order_data';
foreach ($order->get_items() as $item_key => $item_values){
$item_data = $item_values->get_data();
$orderID=$item_data['order_id'];
$prductName=$item_data['name'];
$productPrice=$item_data['subtotal'];
$quantity=$item_data['quantity'];
$subTotal=$item_data['subtotal'];
$total=$item_data['total'];
$tablename=$wpdb->prefix.'seller_order_data';
$data=array(
'order_id' =>$orderID,'product_name' =>$prductName,'product_price' =>$productPrice,'quantity' =>$quantity,'subtotal' =>$subTotal,'total' =>$total
);
$existOrders = $wpdb->get_results( "SELECT order_id FROM $tablename WHERE order_id = $order_id",ARRAY_A );
if(empty($existOrders)){
$wpdb->insert( $tablename,$data);
}
}
/* } */
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com(将#修改为@)