Last active
October 13, 2024 06:57
-
-
Save emre-edu-tech/e853971312f7b155c378e530f8824627 to your computer and use it in GitHub Desktop.
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
<?php | |
// Replace the Add to Cart Button on Single Product Template to go to a link that is also an ACF plugin URL field | |
add_action( 'woocommerce_single_product_summary', 'replace_single_add_to_cart_button', 1 ); | |
function custom_product_button(){ | |
$product = wc_get_product(); | |
// HERE your custom button text and link | |
$button_text = __( "Buy from external resource", "custom-textdomain" ); | |
// Display button | |
echo '<a class="button" style="text-align: center; margin-bottom: 10px;" target="_blank" href="'.get_field('external_product_link', $product->get_id()).'">' . $button_text . '</a>'; | |
} | |
function replace_single_add_to_cart_button() { | |
// Here we completely get rid of Add to Cart button and change it to an external button | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); | |
add_action( 'woocommerce_single_product_summary', 'custom_product_button', 30 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment