因为一个项目,我需要你的帮助。我找了很多,但找不到解决办法。我正在尝试编辑一个名为
woocommerce\\u account\\u订单
我已经添加了该字段
mycustom\\u id
到订单元数据对象,因为我需要在字段mycustom\\u id中获取当前登录用户的所有订单:
(mycustom\\u id=current\\u user\\u id())
检查customer
应该留下来。我只需要再加上这个current_user_id
检查
这应该保持原样:
\'客户\'=>获取当前用户id()
。这是我的无效代码段:
function woocommerce_account_orders( $current_page ) {
$current_page = empty( $current_page ) ? 1 : absint( $current_page );
$customer_orders = wc_get_orders( apply_filters( \'woocommerce_my_account_my_orders_query\', array(
\'customer\' => get_current_user_id(),
\'mycustom_id\' => get_current_user_id(),
\'page\' => $current_page,
\'paginate\' => true,
) ) );
wc_get_template(
\'myaccount/orders.php\',
array(
\'current_page\' => absint( $current_page ),
\'customer_orders\' => $customer_orders,
\'has_orders\' => 0 < $customer_orders->total,
)
);
}
该方法位于:
https://docs.woocommerce.com/wc-apidocs/source-function-woocommerce_account_orders.html#2465-2486如何像过滤器一样智能地将此功能添加到函数中,以及如何以正确的方式将自定义参数传递到函数中?我已将参数保存为order\\u元属性:
[5] => WC_Meta_Data Object (
[current_data:protected] => Array (
[id] => 3477
[key] => mycustom_id
[value] => 2
)
谢谢你的帮助。我已经尝试了很多次,但我对PHP还是新手,必须学习很多。。
SO网友:Scotty G
您可以添加meta_query
分到您的wc_get_orders()
作为唯一的筛选器。。。
function woocommerce_account_orders( $current_page ) {
$current_page = empty( $current_page ) ? 1 : absint( $current_page );
$customer_orders = wc_get_orders( apply_filters( \'woocommerce_my_account_my_orders_query\', array(
\'page\' => $current_page,
\'paginate\' => true,
\'meta_query\' => array(
array(
\'key\' => \'mycustom_id\',
\'value\' => get_current_user_id(),
\'compare\' => \'=\'
)
)
) ) );
wc_get_template(
\'myaccount/orders.php\',
array(
\'current_page\' => absint( $current_page ),
\'customer_orders\' => $customer_orders,
\'has_orders\' => 0 < $customer_orders->total,
)
);
}
这基本上是说,在有订单的地方获取所有订单
meta_key = \'mycustom_id\'
和
meta_value = $current_user_id
.