作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发自定义 WooCommerce 插件。在我的一个函数中,我想使用 wc_create_order()
向系统/数据库添加订单。
下面的代码工作正常,但我找不到将此订单专用于特定用户的方法(因此它显示在后端和该用户的帐户页面上)。
(此数据库字段为:'_customer_user' ???)
我的代码:
// $productid, $userid, $price are passed in the function
$user = get_userdata($userid);
$address = array(
'first_name' => get_user_meta( $userid, "billing_first_name", true),
'last_name' => get_user_meta( $userid, "billing_last_name", true),
'......'
);
$order = wc_create_order();
$args['totals']['subtotal'] = $price;
$args['totals']['total'] = $price;
$order->add_product( get_product( $productid ), 1, $args );
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->calculate_totals();
最佳答案
你可以用 update_post_meta 做到这一点
update_post_meta( $order->id, '_customer_user', $userid );
关于WooCommerce 以编程方式为特定用户添加订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31071415/
在 Rails 中,您可以使用嵌套路由为 has_one 和 has_many 关系创建 RESTful 路由。可以在 Rails Guides 上找到示例 请问有没有什么好的方法可以为habtm关系
我是一名优秀的程序员,十分优秀!