Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannyconnolly/ed2681b23ce9f5e42758 to your computer and use it in GitHub Desktop.
Save dannyconnolly/ed2681b23ce9f5e42758 to your computer and use it in GitHub Desktop.
Add css class to top selling products
/**
* 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