• Resolved ouija

    (@ouija)


    Hi there,

    I’m having an issue with the wcfm_get_user_posts_count() function in the wc-frontend-manager/helpers/wcfm-core-functions.php file, where it is incorrectly calculating the number of posts based on their status.

    For example, all the products have a ‘publish’ status for this one vendor, with 23 published products in total, but when you look at the numbers that wcfm_get_user_posts_count() is generating, they are incorrect:

    It’s showing that 23 products are published, 23 are draft, and 23 are pending (92 in total)… but in reality, only 23 should be shown as published, with 23 in total.

    I’ve been manually changing this function to properly get the product post counts, based on their status, by changing this function like so:

    function wcfm_get_user_posts_count( $user_id = 0, $post_type = 'product', $post_status = 'publish', $custom_args = array() ) {
    	global $wpdb;
        $count = $wpdb->get_var(
            $wpdb->prepare( 
            "
            SELECT COUNT(ID) FROM $wpdb->posts 
            WHERE post_type = %s
            AND post_status = %s
            AND post_author = %d",
            $post_type,
            $post_status,
            $user_id
            )
        );
        return ($count) ? $count : 0;
    }

    Then, the counts are returned correctly based on the actual product post status:

    Just wanted to mention this to have you look into it, as I have to update this function every time an update is released.

    Thank you!

    • This topic was modified 5 years, 9 months ago by ouija.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WC Lovers

    (@wclovers)

    HI,

    Thanks for all the details.

    But our function works perfect.

    Are you getting this issue for Admin or Vendors?

    If for vendors, then which multi-vendor plugin you are using?

    Thank You

    Thread Starter ouija

    (@ouija)

    Happening for Both Admin/Vendors with WC-Vendors Plugin (Free Version)

    Plugin Author WC Lovers

    (@wclovers)

    OK. Well, after next WCFM update use this and do not edit core plugin –

    add_filter( 'wcfm_user_posts_count', function( $count, $user_id, $post_type, $post_status, $custom_args ) {
    	global $wpdb;
      $count = $wpdb->get_var(
    	  $wpdb->prepare( 
    			"
    			SELECT COUNT(ID) FROM $wpdb->posts 
    			WHERE post_type = %s
    			AND post_status = %s
    			AND post_author = %d",
    			$post_type,
    			$post_status,
    			$user_id
    		)
    	);
    	return ($count) ? $count : 0;
    }, 50, 5 );

    Thank You

    Thread Starter ouija

    (@ouija)

    Thank you! Just updated tonight and filter works well! Appreciate it.

    Plugin Author WC Lovers

    (@wclovers)

    Great, you are welcome ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Published/Draft/Pending counts are incorrect based on product status’ is closed to new replies.