我最近安裝了一個非常簡單的插件,它在導航選單之前的 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' );
第一個函式呼叫是我要顯示的頭像,第二個是顯示最近最近訂單的函式。
一切正常,但頭像沒有顯示在“歡迎”段落之前,而是顯示在訂單表的正上方。
我試圖弄亂優先級,但它也不起作用。我錯過了什么?
uj5u.com熱心網友回復:
“一切正常,但頭像沒有顯示在‘歡迎’段落之前,而是顯示在訂單表的正上方。”
這是因為你的回呼函式是在所在
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)然后執行do_actionviaadd_action
add_action( 'my_custom_do_action', 'uafw_show_avatar_woo' );
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/481438.html
標籤:php WordPress woocommerce 钩woocommerce
上一篇:League\Flysystem\Filesystem::delete():引數#1($location)必須是字串型別,給定null,呼叫
下一篇:如何設定表單以將回應發送到某處?
