2017-01-10 53 views
0

我想爲每個註冊的商店客戶顯示自定義歡迎消息。就像「歡迎CUSTOMERNAME!你已經和我們在一起了一年了,要說謝謝,我們給你的折扣是我們店裏10%的一切。」在客戶帳戶儀表板中顯示ACF - Woocommerce

我使用插件Advanced Custom Fields創建了自定義字段welcome_message,並希望在我的客戶的前端帳戶儀表板中顯示它的價值。

在後端,我顯示在用戶個人資料頁面textarea的,我用這個代碼添加字段:

$message = get_field('welcome_message'); echo esc_attr($message);

這段代碼放在這裏:/可溼性粉劑內容/主題/ flatsome-child/woocommerce/myaccount/dashboard.php

但不知何故,價值不會上漲。我也嘗試過,只需the_field('welcome_message');或在WordPress的帳戶頁面添加[acf field="{$welcome_message}"],但這也不起作用。不知何故價值是不會通過。

我希望有人可以幫助我一個小孩。

在此先感謝。

最好的問候

回答

1

有必要將get_field函數連接到用戶。

如:

<?php 
$variable = get_field('field_name', 'user_1'); 
?> 

在直放站領域的情況:

<?php if(have_rows('repeater', 'user_1')): ?> 
<ul> 
<?php while(have_rows('repeater', 'user_1')): the_row(); ?> 
    <li><?php the_sub_field('title'); ?></li> 
<?php endwhile; ?> 
</ul> 
<?php endif; ?> 
+0

謝謝你幫但這並沒有工作。我使用$ current_user_id = get_current_user_id()獲取當前用戶標識;並設置$ variable = get_field('field_name',$ current_user_id);. –

+0

這是錯誤的,如果您看到示例,在user_id之前需要「user_」前綴。 你正確的方法是:$ variable = get_field('field_name','user_'。$ current_user_id); – mariobros

相關問題