在 woocommerce 中,是不是有查看所有订单的简码/页面?
Posted
技术标签:
【中文标题】在 woocommerce 中,是不是有查看所有订单的简码/页面?【英文标题】:in woocommerce, is there a shortcode/page to view all orders?在 woocommerce 中,是否有查看所有订单的简码/页面? 【发布时间】:2015-07-10 21:49:43 【问题描述】:我正在为我的 wordpress 网站使用插件 woocommerce,并且需要一个让会员可以查看其订单历史记录的部分。 woocommerce 中是否有任何简码或页面显示会员的订单历史记录?
【问题讨论】:
【参考方案1】:我的帐户短代码:
[woocommerce_my_account order_count="-1"]
显示“我的帐户”部分,客户可以在其中查看过去的订单并更新他们的信息。您可以指定显示的数量或订单,默认设置为 15(使用 -1 显示所有订单。)
参考:Woocommerce Shortcodes
更新
如果您只需要订单,我不知道是否已经有短代码,但我以 woocommerce_my_account 为例:
function shortcode_my_orders( $atts )
extract( shortcode_atts( array(
'order_count' => -1
), $atts ) );
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
'order_count' => $order_count
) );
return ob_get_clean();
add_shortcode('my_orders', 'shortcode_my_orders');
将此添加到您的 functions.php 文件中,然后像 [my_orders order_counts=10]
一样使用它(order_counts
是可选的,如果缺少它会列出所有订单)。
【讨论】:
实际上它只是将我发送到我的帐户页面,用户可以在我的帐户页面中看到他们的送货地址和欢迎信息。 好的,我试图将上面的代码放在 ROOT/wp-includes/functions.php 中,但它给了我“致命错误:调用 C:\xampp\htdocs\localpressjuicery 中的未定义函数 add_shortcode() \wp-includes\functions.php " 不,是你的主题文件夹中的functions.php文件 好吧,它什么也没显示,因为我目前没有订单,所以让我设置一些假账户/信用卡然后回复你。到目前为止,谢谢。 如何仅按特定优惠券代码过滤订单?【参考方案2】:我正在阅读有关 extract 的内容,显然 Wordpress 不再推荐它。 我找到了这个解决方案,希望对您有所帮助:
function shortcode_my_orders( $atts )
$args= shortcode_atts(
array(
'order_count' => -1
),
$atts
);
$order_count = esc_attr( $args['order_count'] );
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', get_current_user_id() ),
'order_count' => $order_count
) );
return ob_get_clean();
【讨论】:
嗨,我怎样才能包含名称?以上是关于在 woocommerce 中,是不是有查看所有订单的简码/页面?的主要内容,如果未能解决你的问题,请参考以下文章
在 WooCommerce 电子邮件通知中将发件人名称更改为订单元数据中的值