Last active
July 13, 2021 17:20
-
-
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)
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
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