简体   繁体   中英

How to add custom fields to woocommerce shop page with acf

I'am having some difficulties in order to integrate advanced custom fields to the woocommerce shop page. My code is a repeater field and I need to add it to the top of the shop page, but this is not working. I've already tried by adding the page id and nothing happens. Any help or advice would be highly appreciated.

I've created a woocommerce folder inside my child theme, and I am trying to add this code to the archive-product.php template.

<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>

I don't have error messages.

You need to get Woo-commerce Shop Page ID then pass those ID to each 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 } ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM