Check if acf field exist in functions.php

Today i am working in a project. My client requirement was if content exists then only the field visible on single product page. and he wanted to add a product video on the single product page.
also on the field my client also want to popup a video. so first i was installed Easy FancyBox

Then i found a some code on the Easy FancyBox by which i can popup a video easily

<a href="#contact_form_pop" class="fancybox-inline">Product Video</a>

<div style="display:none" class="fancybox-hidden">
    <div id="contact_form_pop" class="hentry" style="width:460px;max-width:100%;">
        //ACF video field goes here
    </div>
</div>

Next step i need to play with it. I have Created a video field on the ACF. ACF field name is product_video

The field only visible on product page

Next is the Big part is to display the product video on single product page. i need to use some div  for popup the product video and all i need to do in functions.php its my big challenge. then i found a solution from ACF support page.

add_action( 'woocommerce_product_thumbnails', 'popup_display_acf_field_under_productgallery', 20 );
function popup_display_acf_field_under_productgallery() {
	
if (get_field('product_video')) {
// your echo statements go here
echo "<a href='#contact_form_pop' class='fancybox-inline popup-vid'>Product video</a>";
echo "<div style='display:none;' class='fancybox-hidden'>";
echo "<div id='contact_form_pop' class='hentry' style='width:460px;max-width:100%;'>";
echo the_field('product_video');
echo "</div>";
echo "</div>";

}
}

Only this code check entire content if exist it will display the popup button.

if (get_field('product_video')) {
  // echo statements go here
  echo the_field('product_video');
 // echo statements go here
}

The front end view:

when click on the Product Video it will popup a video

If you find this post useful comment out.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
0 Shares
Tweet
Share
Pin
Share