0

I need to display two things:

  1. Total number of published WooCommerce products
  2. Total number OF attributes from a term

I can add this in account-bar.php Just need the required inbuilt Woocommerce codes.

Any help is appreciated. Thanks!

2

To get number of woocommerce published products -

$total_products = count( get_posts( array('post_type' => 'product', 'post_status' => 'publish', 'fields' => 'ids', 'posts_per_page' => '-1') ) );

To get attributes count -

$total_attribute_terms = get_terms('pa_'. $attribute_slug, array('hide_empty' => false, 'fields' => 'count') );

The $attribute_slug can be found on Attribute edit page - Wp admin -> Products -> Attributes -> click on fly-out menu edit (not name)

| improve this answer | |
  • Hi Shazzad, Thanks for the reply :) Can I just add this to account-bar.php file or should I use a hook? – user2532458 Dec 15 '13 at 0:00
  • You can add this to your account-bar.php file, just keep note to replace the $attribute_slug to a valid one. – Shazzad Dec 15 '13 at 0:02
  • Shazzad :) I just made some changes to the file, but it doesn't reflect on frontend. pho.to/4KTyT Please check the screenshot. Is there anything I am missing? Sorry, I am so noob in this. – user2532458 Dec 15 '13 at 0:16
  • write it like - <?php _e('Samlet et sted: <b>'. $total_products .' text text text text '. $total_attribute_terms .' text text text </b>'); ?> – Shazzad Dec 15 '13 at 0:25
  • You are a star mate! That did the trick :) – user2532458 Dec 15 '13 at 0:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.