Created
July 22, 2022 17:05
-
-
Save chellestein/ec6461c38d6b3c85cdcd1915b6a0fa13 to your computer and use it in GitHub Desktop.
Replace Woocommerce Add to Cart With Download Link for Paid Membership Pro Users
This file contains 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
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); | |
add_action( 'woocommerce_single_product_summary', 'cs_woocommerce_template_single_add_to_cart', 30 ); | |
/* | |
* replace WooCommerce add-to-cart button with download link when product is downloadable & free for PaidMembershipPro | |
*/ | |
function cs_woocommerce_template_single_add_to_cart() { | |
global $product; | |
if ( pmpro_hasMembershipLevel(array('1','2'))) { | |
$downloads = $product->get_files(); | |
foreach( $downloads as $key => $download ) { | |
echo '<div class="dlbox"><div class="download-link"><a class="dlbutton" href="' . esc_url( $download['file'] ) . '">Download File</a></div></div>'; | |
} | |
} else { | |
do_action( 'woocommerce_' . $product->product_type . '_add_to_cart' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment