我最近安装了一个非常简单的插件,它在woocommerce帐户页面的导航菜单之前显示了用户的化身。
我一直试图包括这个功能,以便在帐户仪表板中显示化身,而不是通过woocommerce_account_dashboard挂钩,但它不是我想要的位置。
在/templates/myaccount/dashboard.php文件中,我做了以下更改:
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
$allowed_html = array(
'a' => array(
'href' => array(),
),
);
?>
<p class="pix-mb-0">
<?php
add_action('woocommerce_account_dashboard', 'uafw_show_avatar_woo', 10, 0 );
printf(
/* translators: 1: user display name 2: logout url */
wp_kses( __( 'Hello %1$s!', 'woocommerce' ), $allowed_html ),
'<strong class="text-yellow">' . esc_html( $current_user->display_name ) . '</strong>',
esc_url( wc_logout_url() )
);
?>
</p>
<p class="text-xs">
<?php $current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
echo __('Account ID: '), $current_user_id; ?>
</p>
<h1 class="h5 text-heading-default font-weight-bold pix-ready pix-mb-10" style="padding-bottom: 0.3em; border-bottom: 1px solid rgba(255,255,255,0.1)">Recent Orders</h1>
<?php add_action( 'woocommerce_account_dashboard', 'action_rorders_woocommerce_account_dashboard', 30, 0 ); ?>
<?php
/**
* My Account dashboard.
*
* @since 2.6.0
*/
do_action( 'woocommerce_account_dashboard' );第一个函数调用是我想要显示的化身,第二个函数显示最近的命令。
一切正常,但化身不是显示在“欢迎”段落之前,而是就在订单表的上方。
我试着把优先次序弄乱,但也没用。我遗漏了什么?
发布于 2022-05-27 06:48:04
“一切正常,但头像没有出现在‘欢迎’段落之前,而是就在订单表的上方。”
--这是因为
add_action的回调函数是在do_action所在的位置执行的。
假设这是您调用的函数的输出:
function uafw_show_avatar_woo() {
echo '<div>Show avatar woo</div>';
}步骤1)然后在模板文件中调用和显示函数,只需使用:
<?php uafw_show_avatar_woo(); ?>或
步骤1)创建自己的do_action,将其添加到要显示回调函数输出的地方:
<?php do_action( 'my_custom_do_action' ); ?>步骤2),然后通过add_action执行do_action
add_action( 'my_custom_do_action', 'uafw_show_avatar_woo' );https://stackoverflow.com/questions/72397821
复制相似问题