<?php
function shortcode_latest_sales( $atts ){
$customer_orders = get_posts( array(
'numberposts' => 5,
'meta_key' => '_customer_user',
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
$output = '<ul class="products pcols-lg-5 pcols-md-4 pcols-xs-2 pcols-ls-1 pwidth-lg-5 pwidth-md-4 pwidth-xs-2 pwidth-ls-1">';
$latest_sold_ids = array();
$count = 0;
foreach ($customer_orders as $order_post) {
$order = wc_get_order( $order_post->ID );
$items = $order->get_items();
foreach ( $items as $item ) {
$latest_sold_ids[] = $item['product_id'];
$product = get_product($item['product_id']);
if($product && $count < 5) {
$output .= '<li class="post-2789 product type-product status-publish has-post-thumbnail product_cat-net product_cat-brand-names product_cat-domain-name product_cat-relationships product_tag-net product_tag-broken-trust product_tag-domain-name instock sold-individually shipping-taxable purchasable product-type-simple recent_sale">';
$output .= '<div class="product-image">';
$output .= '<div class="inner">';
$output .= $product->get_image('full');
$output .= '</div>';
$output .= '</div>';
$output .= '<h3>' . $product->get_title() . '</h3>';
$output .= '</li>';
$count++;
}
}
}
$output .= '</ul>';
return $output;
$args = array(
'post_type' => 'product',
'post__in' => $latest_sold_ids
);
$loop = new WP_Query( $args );
foreach ($latest_sold_ids as $product_id) {
$product = get_product($product_id);
}
}
add_shortcode( 'woo_latest_sales', 'shortcode_latest_sales' );
#вопрос Сейчас происходит вывод всех подряд Order, как подправить что-бы выводились только со статусом Completed?