Skip to content

Instantly share code, notes, and snippets.

@MarceloGlez
Last active July 13, 2021 17:20
Show Gist options
  • Save MarceloGlez/40c5399305badbcac696a0889073d842 to your computer and use it in GitHub Desktop.
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)
/*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