Skip to content

Instantly share code, notes, and snippets.

@MarceloGlez
Last active July 13, 2021 17:20
Show Gist options
  • Save MarceloGlez/4d0aaef07631423785740d76a658b604 to your computer and use it in GitHub Desktop.
Save MarceloGlez/4d0aaef07631423785740d76a658b604 to your computer and use it in GitHub Desktop.
Contador de descargas de un producto en Woocommerce (Agregar líneas de código en function.php del child theme)
add_action( 'woocommerce_single_product_summary', 'show_number_of_downloads' ); function show_number_of_downloads() {
global $wpdb, $product;
if ( empty( $product->id ) ) return;
if ( $product->product_type == 'variable' ) {
$product_ids = $product->get_children();
} else {
$product_ids = array( $product->id );
}
$query = "SELECT SUM( download_count ) AS count
FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions
WHERE product_id IN (".implode( ',', $product_ids ).")";
$count = $wpdb->get_var( $query );
if ( ! empty( $count ) ) {
echo '<p><strong>' . __( 'Veces descargado' ) . '</strong>: ' . $count . '</p>';
} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment