在客户帐户仪表板中显示 ACF - Woocommerce
Show ACF in customer account dashboard - Woocommerce
我想为我的每位注册商店客户显示自定义欢迎消息。像 "Welcome CUSTOMERNAME
! You have been with us for one year now. To say thanks, we are giving you a discount on everything in our shop of 10%."
我已经使用插件 Advanced Custom Fields 创建了一个自定义字段 welcome_message
,并希望在我的前端客户的帐户仪表板中显示它的值。
在后端,我在用户个人资料页面显示文本区域,并使用以下代码添加字段:
$message = get_field( 'welcome_message' );
echo esc_attr( $message );
这段代码放在这里:/wp-content/themes/flatsome-child/woocommerce/myaccount/dashboard.php
但不知何故价值没有出现。我也尝试过简单地使用 the_field('welcome_message');
或在 WordPress 的帐户页面添加 [acf field="{$welcome_message}"]
但这也不起作用。不知何故价值没有通过。
希望有人能帮帮我。
提前致谢。
此致
需要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; ?>
我想为我的每位注册商店客户显示自定义欢迎消息。像 "Welcome CUSTOMERNAME
! You have been with us for one year now. To say thanks, we are giving you a discount on everything in our shop of 10%."
我已经使用插件 Advanced Custom Fields 创建了一个自定义字段 welcome_message
,并希望在我的前端客户的帐户仪表板中显示它的值。
在后端,我在用户个人资料页面显示文本区域,并使用以下代码添加字段:
$message = get_field( 'welcome_message' );
echo esc_attr( $message );
这段代码放在这里:/wp-content/themes/flatsome-child/woocommerce/myaccount/dashboard.php
但不知何故价值没有出现。我也尝试过简单地使用 the_field('welcome_message');
或在 WordPress 的帐户页面添加 [acf field="{$welcome_message}"]
但这也不起作用。不知何故价值没有通过。
希望有人能帮帮我。
提前致谢。
此致
需要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; ?>