php - 如何使用 acf 将自定义字段添加到 woocommerce 商店页面
问题描述
为了将高级自定义字段集成到 woocommerce 商店页面,我遇到了一些困难。我的代码是一个转发器字段,我需要将它添加到商店页面的顶部,但这不起作用。我已经尝试通过添加页面 id 并且没有任何反应。任何帮助或建议将不胜感激。
我在我的子主题中创建了一个 woocommerce 文件夹,我正在尝试将此代码添加到 archive-product.php 模板。
<div class="container accueil">
<h2 class="titre-section">Tous nos saveurs à un seul clic !</h2>
<div class="row products-categories">
<?php if( have_rows('categories_menu') ): ?>
<?php while( have_rows('categories_menu') ): the_row();
// vars
$titre = get_sub_field('titre_categorie');
$image = get_sub_field('image_categorie');
?>
<a class="link-cat" href="/carte/">
<div class="col-md-4 product-cat" style="background-image: url(<?php echo $image['url']; ?>);">
<h2 class="cat-title"><?php echo $titre; ?></h2>
</div>
</a>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
我没有错误消息。
解决方案
您需要获取 Woo-commerce 商店页面 ID,然后将这些 ID 传递给每个 get_field & rows
<?php if(is_shop()){ ?>
<div class="container accueil">
<h2 class="titre-section">Tous nos saveurs à un seul clic !</h2>
<div class="row products-categories">
<?php $post_id = get_option( 'woocommerce_shop_page_id' ); ?>
<?php if( have_rows('categories_menu', $post_id) ): ?>
<?php while( have_rows('categories_menu', $post_id) ): the_row();
$titre = get_sub_field('titre_categorie', $post_id);
$image = get_sub_field('image_categorie', $post_id);
?>
<a class="link-cat" href="/carte/">
<div class="col-md-4 product-cat" style="background-image: url(<?php echo $image['url']; ?>);">
<h2 class="cat-title"><?php echo $titre; ?></h2>
</div>
</a>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
<?php } ?>
推荐阅读
- python - 如何访问第二个
在硒(Python)中?
- angular - 在单站点 Angular 应用程序上使用 Matomo 进行动作之间的时间跟踪
- mysql - MySQL - 如何根据前一行中的值查找行
- obs - Ubuntu 上的 OSB/桌面音频无法定向到 Streamyard/Chrome 麦克风
- java - 如何更新或覆盖 libGdx 中的首选项值
- django - 序列化时选择字段的人类可读值
- android - 抽象协程结构
- c# - 在 Xamain 中从后面的代码中设置 {Binding .} 的等效项?
- javascript - 过滤功能运行太晚了一步
- spring - 更改 OpenAPI 的自动生成 HomeController