[英]Displays Woocommerce My Account Orders instead of Dashboard
我正在尝试让 url.com/my-account 或简码 [woocommerce_my_account] 显示订单,而不是显示“Hello User(not user)?”的仪表板。
我唯一拥有的是在登录后重定向到订单而不是仪表板,但是然后我去 /my-account 仍然显示我不想要的仪表板。
我发现最接近我想要的代码是......
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
return do_shortcode('[woocommerce_my_account]');
}else{
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', $user_id),
'order_count' => $order_count
) );
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
但是,如果没有下订单,则显示为空白(不显示“尚未下订单。”带有商店按钮)并且我的帐户导航侧边栏不显示。 我是否必须为此制作一个自定义页面模板才能添加到 woocommerce 帐户导航侧边栏中?
编辑:如果我使用 orders.php 而不是 my-orders.php 那么我可以获得“尚未下订单”。 但仍然没有侧边栏导航
我正在尝试使 url.com/my-account 或短代码 [woocommerce_my_account] 显示订单,而不是显示“您好用户(不是用户)?”的仪表板。
我唯一拥有的是登录后重定向到订单而不是仪表板,但我然后转到 /my-account 仍然显示我不想要的仪表板。
我发现的最接近我想要的代码是......
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
return do_shortcode('[woocommerce_my_account]');
}else{
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', $user_id),
'order_count' => $order_count
) );
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
但是,如果没有下订单,则显示为空白(不显示“尚未下订单。”带有商店按钮)并且我的帐户导航侧栏不显示。 我是否必须为此创建一个自定义页面模板才能添加到 woocommerce 帐户导航侧栏中?
编辑:如果我使用 orders.php 而不是 my-orders.php 那么我能够得到“尚未下订单”。 但仍然没有侧边栏导航
我正在尝试使 url.com/my-account 或短代码 [woocommerce_my_account] 显示订单,而不是显示“您好用户(不是用户)?”的仪表板。
我唯一拥有的是登录后重定向到订单而不是仪表板,但我然后转到 /my-account 仍然显示我不想要的仪表板。
我发现的最接近我想要的代码是......
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
return do_shortcode('[woocommerce_my_account]');
}else{
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', $user_id),
'order_count' => $order_count
) );
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
但是,如果没有下订单,则显示为空白(不显示“尚未下订单。”带有商店按钮)并且我的帐户导航侧栏不显示。 我是否必须为此创建一个自定义页面模板才能添加到 woocommerce 帐户导航侧栏中?
编辑:如果我使用 orders.php 而不是 my-orders.php 那么我能够得到“尚未下订单”。 但仍然没有侧边栏导航
我正在尝试使 url.com/my-account 或短代码 [woocommerce_my_account] 显示订单,而不是显示“您好用户(不是用户)?”的仪表板。
我唯一拥有的是登录后重定向到订单而不是仪表板,但我然后转到 /my-account 仍然显示我不想要的仪表板。
我发现的最接近我想要的代码是......
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
return do_shortcode('[woocommerce_my_account]');
}else{
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', $user_id),
'order_count' => $order_count
) );
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
但是,如果没有下订单,则显示为空白(不显示“尚未下订单。”带有商店按钮)并且我的帐户导航侧栏不显示。 我是否必须为此创建一个自定义页面模板才能添加到 woocommerce 帐户导航侧栏中?
编辑:如果我使用 orders.php 而不是 my-orders.php 那么我能够得到“尚未下订单”。 但仍然没有侧边栏导航
我正在尝试使 url.com/my-account 或短代码 [woocommerce_my_account] 显示订单,而不是显示“您好用户(不是用户)?”的仪表板。
我唯一拥有的是登录后重定向到订单而不是仪表板,但我然后转到 /my-account 仍然显示我不想要的仪表板。
我发现的最接近我想要的代码是......
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
return do_shortcode('[woocommerce_my_account]');
}else{
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', $user_id),
'order_count' => $order_count
) );
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
但是,如果没有下订单,则显示为空白(不显示“尚未下订单。”带有商店按钮)并且我的帐户导航侧栏不显示。 我是否必须为此创建一个自定义页面模板才能添加到 woocommerce 帐户导航侧栏中?
编辑:如果我使用 orders.php 而不是 my-orders.php 那么我能够得到“尚未下订单”。 但仍然没有侧边栏导航
截至今天,只有一种解决方法可以将另一个“我的帐户”选项卡设置为默认选项,同时保留“仪表板”选项卡。
假设我们要默认使用“下载”选项卡。 我们要:
这在此处粘贴有点复杂,因此我将仅介绍最困难的第 1 点。 rest 可以在 StackOverflow 或本Business Bloomer 教程上轻松找到,因为它的基本重命名/删除/添加我的帐户选项卡有效。
根据第 1 点,我们需要覆盖 woocommerce_account_content() function 负责默认显示“仪表板”内容,以防我们在“我的帐户”上并且没有查询变量或有非空查询变量称为“页面名称”。
因此,我将删除 WooCommerce function,并添加我的版本:
add_action( 'woocommerce_account_content', 'bbloomer_myaccount_replace_dashboard_content', 1 );
function bbloomer_myaccount_replace_dashboard_content() {
remove_action( 'woocommerce_account_content', 'woocommerce_account_content', 10 );
add_action( 'woocommerce_account_content', 'bbloomer_account_content' );
}
现在我 go 定义了我的自定义 bbloomer_account_content() function,我基本上告诉系统:
代码:
function bbloomer_account_content() {
global $wp;
if ( empty( $query_vars = $wp->query_vars ) || ( ! empty( $query_vars ) && ! empty( $query_vars['pagename'] ) ) ) {
woocommerce_account_downloads();
} else {
foreach ( $wp->query_vars as $key => $value ) {
if ( 'pagename' === $key ) {
continue;
}
if ( has_action( 'woocommerce_account_' . $key . '_endpoint' ) ) {
do_action( 'woocommerce_account_' . $key . '_endpoint', $value );
return;
}
}
}
}
这样,如果我 go 到“example.com/my-account”我会看到“Downloads”标签内容; 如果我将选项卡和 go 切换到“仪表板”或“订单”,我将看到它们的原始内容。
请记住,这只是第 1 部分,因此第 2、3 和 4 部分需要额外的解决方法才能真正发挥作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.