Noptin_WooCommerce::get_product_purchase_count( $customer_id_or_email = null,  $product_id )


Source Source

File: includes/integrations/class-noptin-woocommerce.php

	public function get_product_purchase_count( $customer_id_or_email = null, $product_id ) {

		$orders = wc_get_orders(
			array(
				'limit'    => -1,
				'customer' => $customer_id_or_email,
				'status'   => array( 'wc-completed', 'wc-processing', 'wc-refunded' ),
			)
		);

		$count = 0;

		// Loop through each order.
   		foreach ( $orders as $order ) {

			// Fetch the items.
			$items = $order->get_items();
			  
			// Compare each product to our product.
      		foreach ( $items as $item ) {
				$item = $this->get_order_item_details( $item );

        		if ( $product_id == $item['product_id'] ) {
            		$count += 1;
         		} else if( $product_id == $item['variation_id'] ) {
					$count += 1;
				}
    		}
   		}

		return $count;

	}


Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation