Last active
December 20, 2022 11:43
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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