Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress WooCommerce,显示所有购买的产品,不包括副本_Wordpress_Woocommerce_Shortcode - Fatal编程技术网

Wordpress WooCommerce,显示所有购买的产品,不包括副本

Wordpress WooCommerce,显示所有购买的产品,不包括副本,wordpress,woocommerce,shortcode,Wordpress,Woocommerce,Shortcode,以下内容用于显示所有已购买的产品,但我需要它不要多次显示产品(如果产品已购买多次,则会发生这种情况): 从 //show "Products purchased" pg in My Acct function products_bought_by_curr_user() { // GET CURR USER $current_user = wp_get_current_user(); if ( 0 == $current_user->ID ) r

以下内容用于显示所有已购买的产品,但我需要它不要多次显示产品(如果产品已购买多次,则会发生这种情况):

//show "Products purchased" pg in My Acct
function products_bought_by_curr_user() {
    // GET CURR USER
    $current_user = wp_get_current_user();
    if ( 0 == $current_user->ID ) return;
    // GET USER ORDERS (COMPLETED + PROCESSING)
    $customer_orders = get_posts( array(
        'numberposts' => -1,
        'meta_key'    => '_customer_user',
        'meta_value'  => $current_user->ID,
        'post_type'   => wc_get_order_types(),
        'post_status' => array_keys( wc_get_is_paid_statuses() ),
    ) );
    // LOOP THROUGH ORDERS AND GET PRODUCT IDS
    if ( ! $customer_orders ) return;
    $product_ids = array();
    foreach ( $customer_orders as $customer_order ) {
        $order = wc_get_order( $customer_order->ID );
        $items = $order->get_items();
        foreach ( $items as $item ) {
            $product_id = $item->get_product_id();
            $product_ids[] = $product_id;
        }
    }
    $product_ids = array_unique( $product_ids );
    $product_ids_str = implode( ",", $product_ids );
    // PASS PRODUCT IDS TO PRODUCTS SHORTCODE
    return do_shortcode("[products ids='$product_ids_str']");
}
add_shortcode( 'my_purchased_products', 'products_bought_by_curr_user' );