Skip to content

Instantly share code, notes, and snippets.

@askwpgirl
Created December 7, 2019 02:59
Show Gist options
  • Save askwpgirl/c9f808c9dec87d1847e542d7c5c95079 to your computer and use it in GitHub Desktop.
Save askwpgirl/c9f808c9dec87d1847e542d7c5c95079 to your computer and use it in GitHub Desktop.
Sample function with ACF field loaded into WooCommerce single product hook
<?php
//Paste the content below into your your child theme's functions.php file
//Do not past the <?php above
//This is your function name
function my_woo_custom_fields() {
//this stops PHP, so we can work in HTML
//replace text_field with your field
?>
<?php if( get_field('text_field') ): ?>
<h2><?php the_field('text_field'); ?></h2>
<?php endif; ?>
<?php
//this starts PHP, so we can close the function
}
//This is the action to hook your function into the appropriate place in your single product template
//The number changes the position relative to the other functions from WC hooked into this same hook
add_action('woocommerce_single_product_summary','my_woo_custom_fields', 45);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment