Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active December 20, 2022 11:43
Show Gist options
  • Save braddalton/9b77f8925230511119a57a96f468ef13 to your computer and use it in GitHub Desktop.
Save braddalton/9b77f8925230511119a57a96f468ef13 to your computer and use it in GitHub Desktop.
Custom button before Add to Cart form in WooCommerce Product Page https://wpsites.net/?p=111272
add_action( 'woocommerce_before_add_to_cart_form', 'custom_field_button' );
function custom_field_button() {
$wp = get_post_meta( get_the_ID(), 'wp_button', true );
$acf = class_exists('acf') ? get_field('acf_button') : '';
$field = $acf ? $acf : $wp;
if ( $field && is_singular('product') ) {
printf( '<a href="%s" class="button" target="_blank" rel="”nofollow” noopener">' . __( 'Custom Button' ) . '</a>', $field );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment