Advertisement
Fany_VanDaal

Zobrazení celkového počtu produktů skladem

Jan 14th, 2021
777
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None
  1. //od Roman Meidl
  2. add_shortcode( 'celkem-produktu', 'get_instock_products_count' );
  3. function get_instock_products_count(){
  4. global $wpdb;
  5. // The SQL query
  6. $result = $wpdb->get_col( "
  7. SELECT COUNT(p.ID)
  8. FROM {$wpdb->prefix}posts as p
  9. INNER JOIN {$wpdb->prefix}postmeta as pm ON p.ID = pm.post_id
  10. WHERE p.post_type LIKE '%product%'
  11. AND p.post_status LIKE 'publish'
  12. AND pm.meta_key LIKE '_stock_status'
  13. AND pm.meta_value LIKE 'instock'
  14. " );
  15. return reset($result);
  16. }
Advertisement
RAW Paste Data Copied
Advertisement