Created
April 13, 2015 13:08
-
-
Save dannyconnolly/ed2681b23ce9f5e42758 to your computer and use it in GitHub Desktop.
Add css class to top selling products
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 topseller class to product | |
**/ | |
$query = "SELECT ID FROM {$wpdb->posts} p | |
INNER JOIN {$wpdb->postmeta} pm ON ( pm.post_id = p.ID AND pm.meta_key='total_sales' ) | |
WHERE p.post_type = 'product' | |
AND p.post_status = 'publish' | |
ORDER BY pm.meta_value+0 DESC | |
LIMIT 10"; | |
$topselled_ids = $wpdb->get_results( $wpdb->prepare($query,OBJECT )); | |
/*echo '<pre>'; | |
var_dump($topselled_ids ); | |
echo '</pre>';*/ | |
foreach ($topselled_ids as $one_topselled_id){ | |
$topselled[] = $one_topselled_id->ID; | |
} | |
if ( in_array($post->ID, $topselled)) | |
$classes[] = "top_selled"; | |
/** | |
* End Add topseller class to product | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment