在WooCommerce商店主页和类别列表中显示ACF自定义字段



我正在尝试在html列表标签中在我的WooCommerce店面上显示高级自定义字段。我修改了文件:

content-product_cat.php

由此:

<li <?php wc_product_cat_class( '', $category ); ?>>

对此:

<li style="background: <?php the_field('my_ACF_field'); ?>" <?php wc_product_cat_class( '', $category ); ?>>

我还在我的WP后端添加了ACF字段,并将其分配给我的页面"商店",这是WooCommerce店面。我可以在我的后端(商店页面(上填写输入,但它没有显示在店面/类别页面上,只是没有通过。问题出在哪里?

我还尝试将此字段设置为分类法,并将其显示在WooCommerce中的类别设置中,也没有成功。

我认为您需要在 ACF the_field上使用第二个参数来获取您所追求的特定对象的值。 例如,如果您在产品类别上设置了 ACF 字段,则需要传入您当前正在查看的术语以获得正确的值。

我相信在类别页面上,您需要使用类似

<li style="background: <?php the_field('my_ACF_field', $category);?>" <?php wc_product_cat_class( '', $category ); ?>>

此 ACF 文档字段提供了有关向分类术语添加字段的更多详细信息:https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

最新更新