<?php if (is_user_logged_in()): ?>
<section>
<?php echo do_shortcode('[block id="purchased_tablet_products"]'); ?>
</section>
<?php endif; ?>
add_shortcode( 'display_misha_purchased_products', 'misha_populate_products_page' );
add_action( 'woocommerce_account_purchased-products_endpoint', 'misha_populate_products_page' );
function misha_populate_products_page() {
global $wpdb;
$purchased_products_ids = $wpdb->get_col( $wpdb->prepare(
"
SELECT itemmeta.meta_value
FROM " . $wpdb->prefix . "woocommerce_order_itemmeta itemmeta
INNER JOIN " . $wpdb->prefix . "woocommerce_order_items items
ON itemmeta.order_item_id = items.order_item_id
INNER JOIN $wpdb->posts orders
ON orders.ID = items.order_id
INNER JOIN $wpdb->postmeta ordermeta
ON orders.ID = ordermeta.post_id
WHERE itemmeta.meta_key = '_product_id'
AND ordermeta.meta_key = '_customer_user'
AND ordermeta.meta_value = %s
ORDER BY orders.post_date ASC
",
get_current_user_id()
) );
$purchased_products_ids = array_unique( $purchased_products_ids );
if( !empty( $purchased_products_ids ) ) :
$purchased_products = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
'post__in' => $purchased_products_ids,
'posts_per_page' => -1,
'orderby' => 'post__in'
) );
echo '<div class="woocommerce columns-3">';
woocommerce_product_loop_start();
while ( $purchased_products->have_posts() ) : $purchased_products->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
woocommerce_product_loop_end();
woocommerce_reset_loop();
wp_reset_postdata();
echo '</div>';
else:
echo 'Nothing purchased yet.';
endif;
}
add_action( 'woocommerce_account_purchased-products_endpoint', 'misha_purchased_products_page' );
function misha_purchased_products_page() {
global $wpdb;
$purchased_products_ids = $wpdb->get_col( $wpdb->prepare(
"
SELECT itemmeta.meta_value
FROM " . $wpdb->prefix . "woocommerce_order_itemmeta itemmeta
INNER JOIN " . $wpdb->prefix . "woocommerce_order_items items
ON itemmeta.order_item_id = items.order_item_id
INNER JOIN $wpdb->posts orders
ON orders.ID = items.order_id
INNER JOIN $wpdb->postmeta ordermeta
ON orders.ID = ordermeta.post_id
WHERE itemmeta.meta_key = '_product_id'
AND ordermeta.meta_key = '_customer_user'
AND ordermeta.meta_value = %s
ORDER BY orders.post_date DESC
",
get_current_user_id()
) );
$purchased_products_ids = array_unique( $purchased_products_ids );
if( !empty( $purchased_products_ids ) ) :
$purchased_products = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
'post__in' => $purchased_products_ids,
'posts_per_page' => 6,
'orderby' => 'post__in'
) );
echo '<div class="woocommerce columns-3">';
woocommerce_product_loop_start();
while ( $purchased_products->have_posts() ) : $purchased_products->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
woocommerce_product_loop_end();
woocommerce_reset_loop();
wp_reset_postdata();
echo '</div>';
else:
echo 'Nothing purchased yet.';
endif;
}
add_shortcode( 'display_purchased_products', 'misha_purchased_products_page' );
add_action( 'woocommerce_account_purchased-products_endpoint', 'mobile_purchased_products_page' );
function mobile_purchased_products_page() {
global $wpdb;
$purchased_products_ids = $wpdb->get_col( $wpdb->prepare(
"
SELECT itemmeta.meta_value
FROM " . $wpdb->prefix . "woocommerce_order_itemmeta itemmeta
INNER JOIN " . $wpdb->prefix . "woocommerce_order_items items
ON itemmeta.order_item_id = items.order_item_id
INNER JOIN $wpdb->posts orders
ON orders.ID = items.order_id
INNER JOIN $wpdb->postmeta ordermeta
ON orders.ID = ordermeta.post_id
WHERE itemmeta.meta_key = '_product_id'
AND ordermeta.meta_key = '_customer_user'
AND ordermeta.meta_value = %s
ORDER BY orders.post_date DESC
",
get_current_user_id()
) );
$purchased_products_ids = array_unique( $purchased_products_ids );
if( !empty( $purchased_products_ids ) ) :
$purchased_products = new WP_Query( array(
'post_type' => 'product',
'post_status' => 'publish',
'post__in' => $purchased_products_ids,
'posts_per_page' => 4,
'orderby' => 'post__in'
) );
echo '<div>';
woocommerce_product_loop_start();
while ( $purchased_products->have_posts() ) : $purchased_products->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
woocommerce_product_loop_end();
woocommerce_reset_loop();
wp_reset_postdata();
echo '</div>';
else:
echo 'Nothing purchased yet.';
endif;
}
add_shortcode( 'display_mobile_purchased_products', 'mobile_purchased_products_page' );