Home › Forums › General Issues › Fields from pages to product (woocommerce) › Reply To: Fields from pages to product (woocommerce)
For some annoying reason my last reply was just gone, but I managed to restore it somehow. Maybe I pushed the wrong button, so please excuse any mail spam that might occur now.
By your current setup this particular page (“Banner 1”) and all products each are given two fields: A link and a banner. Now you can assign them a link and a banner each. So, if you call
get_field( 'my_custom_link_in_pages' ) on a product page, you are grabbing the link that you have assigned to this product. If you have not assigned this product a link, the function will return an empty value.
Depending on what exactly your are trying to accomplish, there are three ways to solve this:
1. You can assign your product the same link and banner that you have assigned “Banner 1”, so they now belong to the product as well.
2. You can fetch the fields of “Banner 1” directly on every product page like this:
<?php get_field( 'my_custom_link_in_pages' , $the_id_of_the_banner1_page )
3. You can remove the second field group condition, so the fields no longer apply to product pages, then create a second field group, which contains a
Post Object field, and then assign each product a page, the link and banner of which to use, like this:
<?php $the_page_id = get_field( 'the_assigned_page' ); is_object( $the_page_id ) ? $the_page_id = $the_page_id->ID : null ; $the_link = get_field( 'my_custom_link_in_pages' , $the_page_id );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.