admin 管理员组

文章数量: 1184232

How can I output the contents of my account > orders on a different page in php?

I managed to output the table when there are orders, but when there are no orders, it shows blank.

How can I show the orders content when blank in a different php page?

Thanks!

How can I output the contents of my account > orders on a different page in php?

I managed to output the table when there are orders, but when there are no orders, it shows blank.

How can I show the orders content when blank in a different php page?

Thanks!

Share Improve this question asked Jan 21, 2019 at 13:38 KarenSKarenS 112 bronze badges 2
  • What do you have so far? – RiddleMeThis Commented Jan 21, 2019 at 13:52
  • This shows my full order table but not the empty message . /* Show Orders inside My Account Page */ function shortcode_my_orders_two( $atts ) { extract( shortcode_atts( array( 'order_count' => -1 ), $atts ) ); ob_start(); wc_get_template( 'myaccount/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_two', 'shortcode_my_orders_two'); – KarenS Commented Jan 23, 2019 at 14:24
Add a comment  | 

1 Answer 1

Reset to default 0

If you look at the template file for orders it starts like this

do_action( 'woocommerce_before_account_orders', $has_orders ); ?>

<?php if ( $has_orders ) : ?>

If there are no orders it's never going to loop through that content, which is good because it would be broken if it did. If you really need the orders table to show up even if it's empty then you'll want to recreate the table from the template file somewhere else and pull that in. If you're including this template on your other page it shouldn't be showing up as blank with no orders though, there should be a no orders message.

本文标签: How can I put the contents of My Account gt Order into a separate page WooCommerce