Last active
July 13, 2021 17:20
-
-
Save MarceloGlez/40c5399305badbcac696a0889073d842 to your computer and use it in GitHub Desktop.
Enlace de descarga directa de producto comprado en su propia página de producto en Woocommerce (Agregar líneas de código en function.php del child theme)
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
/*Enlace de descarga directa de producto comprado en página de producto*/ | |
add_action('woocommerce_after_add_to_cart_form', 'download_products'); | |
function download_products() | |
{ | |
global $product; | |
$downloads = array(); | |
$user_id = get_current_user_id(); | |
$downloads = wc_get_customer_available_downloads($user_id); | |
if (!empty($downloads)) { | |
foreach ($downloads as $download) { | |
if ($download['product_id'] === $product->get_id()) { | |
echo '<a href="' . $download['download_url'] . '">Descargar</a>'; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment