1

我试图在前端更新客户的结算明细。我有下面的代码:wc_update_order()不按预期方式工作

if(isset($_POST['save_order'])){ 
    $update_billing_details = wc_update_order(array('order_id' => $update_order_id)); 
    $update_order_args = array(
     'first_name' => $_POST['billing_first_name'] 
    ); 
$update_billing_details->set_address($update_order_args, 'billing'); 
if($update_billing_details){ 
    echo "success"; 
} 
} 

会发生什么是,第一个名字是在点击保存按钮TWICE后更新。

例子:

原名为 '约翰'。如果我把它做成'约翰尼'并且保存,它仍然显示'约翰'。如果我输入名称'Johndel',然后点击保存,它会变成'Johnny',依此类推。

但是,如果我做我的代码是这样的:

if(isset($_POST['save_order'])){ 
    $update_order_args = array(
       '_billing_first_name' => $_POST['billing_first_name'], 
       'order_id' => $update_order_id 
       ); 
    $update_billing_details = wc_update_order($update_order_args); 
} 

没有发生的事情。

我在做什么错?我根据我的工作通过this question

任何帮助,高度赞赏。

感谢,

-Eli

回答

1

你可以尝试使用,而不是update_post_meta()功能,这样一来:

if(isset($_POST['save_order']) && isset($_POST['billing_first_name'])){ 
    update_post_meta($update_order_id, '_billing_first_name', sanitize_text_field($_POST['billing_first_name'])); 
} 

你必须确保$update_order_id是这里所定义的订单ID 。

由于我不能测试这个我不能保证任何东西......我希望这会起作用。