I was working on a project and I ran into a situation where a client wanted to add dynamic content below the single product short description in Woocommerce. So I decided to create an article discussing 2 examples on how to use this: a basic use case and a more advanced scenario involving Advanced Custom Fields (ACF).
Basic Example
add_action( 'woocommerce_single_product_summary', 'hjs_below_single_product_summary', 20 ); | |
function hjs_below_single_product_summary() { | |
// Add Your Additional Content Here | |
} |
The Basic Use Case above hooks into the location right below the single product summary in WooCommerce. You can pretty much add any content you want inside this function. You could add static HTML or dynamic PHP or even a WordPress shortcode. Whatever you add will output below the product short description on every product!
Advanced Example
add_action( 'woocommerce_single_product_summary', 'hjs_video_below_single_product_summary', 20 ); | |
function hjs_video_below_single_product_summary() { | |
$video_id = get_field('product_video_id'); ?> | |
<div class="product-video"> | |
<a class="popup-youtube button" href="http://www.youtube.com/watch?v=<?php echo $video_id; ?>&rel=0&controls=0&showinfo=0">Watch Video</a> | |
</div> | |
<?php } |
In this example, we are using the same base code from the basic example, however, I have added code to pull an ACF field, which in this case contains a Youtube video ID, into the snippet. I am then adding that video ID into a Magnific Youtube Popup link.
So this code allows the owner of the website to add in a product video id on the product page and then it will dynamically display that product video in a simple popup when the button is clicked!
Leave a Reply