Skip to content

Instantly share code, notes, and snippets.

@noellesteegs
Last active February 21, 2021 21:57
Show Gist options
  • Save noellesteegs/d71951e0bada8f89aa388a1f098cbd2d to your computer and use it in GitHub Desktop.
Save noellesteegs/d71951e0bada8f89aa388a1f098cbd2d to your computer and use it in GitHub Desktop.
<?php
// Determines what to do - creates the function with your function name
function add_note_to_product() {
// Checks whether the product is in the Hoodies product category
if ( has_term('hoodies', 'product_cat' ) ) {
// Gets the note field
$note = get_field( 'note' );
// Checks whether the field has text in it
if( $note ) {
// Outputs the text you entered in the backend
echo '<p class="my-product-note">' . $note . '</p>';
}
}
}
// Determines where to do it - the first part is the hook, the second your function name
add_action( 'woocommerce_after_add_to_cart_button', 'add_note_to_product' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment