My products
global $wpdb;
$current_user = wp_get_current_user();
$customer_email = $current_user->user_email;
$customer_data = array( $customer_email );
$statuses = array_map( ‘esc_sql’, wc_get_is_paid_statuses() );
$result = $wpdb->get_col( ”
SELECT im.meta_value FROM {$wpdb->posts} AS p
INNER JOIN {$wpdb->postmeta} AS pm ON p.ID = pm.post_id
INNER JOIN {$wpdb->prefix}woocommerce_order_items AS i ON p.ID = i.order_id
INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS im ON i.order_item_id = im.order_item_id
WHERE p.post_status IN ( ‘wc-” . implode( “‘,’wc-“, $statuses ) . “‘ )
AND pm.meta_key IN ( ‘_billing_email’, ‘_customer_user’ )
AND im.meta_key IN ( ‘_product_id’, ‘_variation_id’ )
AND im.meta_value != 0
AND pm.meta_value IN ( ‘” . implode( “‘,'”, $customer_data ) . “‘ )
” );
$product_ids = array_map( ‘absint’, $result );
if ( !empty( $product_ids ) ) {
$args = array(
‘post_type’ => ‘product’,
‘post__in’ => $product_ids,
‘posts_per_page’ => 12
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) :
$loop->the_post();
woocommerce_get_template_part( ‘content’, ‘product’ );
endwhile;
} else {
echo __( ‘No products found’ );
}
wp_reset_postdata();
} else {
echo __( ‘No products found’ );
}
[/insert_php]