Wordpress 在“添加”旁边添加一些图像;“添加到购物车”;按钮

Wordpress 在“添加”旁边添加一些图像;“添加到购物车”;按钮,wordpress,woocommerce,advanced-custom-fields,Wordpress,Woocommerce,Advanced Custom Fields,我需要一个图像出现在旁边添加到购物车按钮在WooCommerce产品页面,使用先进的自定义字段插件。如我所知,为了显示值,必须将_字段函数添加到某个页面模板中。在哪个模板文件中,我应该在哪里放置_字段函数?这取决于您使用的“添加到购物车”类型(简单产品、变量等) 不管怎样,每个都在这个目录中(对于单个产品):templates/single-product/add-to-cart 您应该(为了获得最佳效果)将图像阵列用于ACF内容 您可以这样写(将get\u字段('image')更改为get\u

我需要一个图像出现在旁边添加到购物车按钮在WooCommerce产品页面,使用先进的自定义字段插件。如我所知,为了显示值,必须将_字段函数添加到某个页面模板中。在哪个模板文件中,我应该在哪里放置_字段函数?

这取决于您使用的“添加到购物车”类型(简单产品、变量等)

不管怎样,每个都在这个目录中(对于单个产品):
templates/single-product/add-to-cart

您应该(为了获得最佳效果)将图像阵列用于ACF内容

您可以这样写(将
get\u字段('image')
更改为
get\u字段('your\u field\u name')


“alt=”“/>
如果需要基本显示,可以使用图像URL并执行以下操作:

<?php if( get_field('image') ): ?> <!--only shows the image field if it exists (an image was uploaded through ACF)-->

    <img src="<?php the_field('image'); ?>" /> <!--displays the URL of the image if it is not an array/ID set in ACF field parameters, but a URL -->

<?php endif; ?> <!-- end the IF statement -->

" /> 

如果可能的话,我更喜欢使用alt标记。

是的!这正是我想要的。我的php很差,你能给我一个源代码来解释你上面写的代码,这样我就可以编辑它吗?我会在上面添加注释。它来自ACF,但他们希望你了解php。
<?php if( get_field('image') ): ?> <!--only shows the image field if it exists (an image was uploaded through ACF)-->

    <img src="<?php the_field('image'); ?>" /> <!--displays the URL of the image if it is not an array/ID set in ACF field parameters, but a URL -->

<?php endif; ?> <!-- end the IF statement -->