亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WooCommerce 我的帳戶 - 下載:列出所有產品

WooCommerce 我的帳戶 - 下載:列出所有產品

PHP
慕婉清6462132 2022-11-04 17:29:17
在我的網站上,我只提供虛擬產品,這就是為什么我想在我的帳戶中進行更改 - 下載視圖。我正在使用以下代碼。function filter_woocommerce_customer_available_downloads($downloads, $customer_id) {     // Manipulate download data here, this example we'll get the first 5 downloads in the array    // $downloads = array_slice($downloads, 0, 5); // Sorting the array by Order Ids in DESC order        arsort($downloads);     // Return first five downloads    return $downloads;}; // Add the filter, this tells wordpress to apply this filter every time available downloads is calledadd_filter( 'woocommerce_customer_available_downloads', 'filter_woocommerce_customer_available_downloads', 10, 2 );/** * Group Downloadable products by product ID * * @param array $downloads * @return array */function prefix_group_downloadable_products( array $downloads ) {    $unique_downloads = [];    foreach ($downloads as $download ) {        $list = [            'download_url' => $download['download_url'],            'file_name'    => $download['file']['name'],            'orderid'  => $download['order_id']        ];        if ( array_key_exists( $download['product_id'], $unique_downloads ) ) {            $unique_downloads[ $download['product_id'] ]['list'][] = $list;            continue;        }        $data = $download;        $data['list'] = [ $list ];        $unique_downloads[ $download['product_id'] ] = $data;    }    return $unique_downloads;}add_filter( 'woocommerce_customer_get_downloadable_products', 'prefix_group_downloadable_products' );/** * Show number list of downloadable files for group product * * @param array $download * @return void */function prefix_downloads_column_download_file( array $download ) {    $lists = $download['list'];            // Sorting the array by Order Ids in DESC order        arsort($lists);     if ( empty( $lists ) ) {        _e( 'No Download Files', 'storefront' );        return;    }    }但是,訂單日期顯示在每個下載鏈接上方。我只需要在所有鏈接上都有日期。(按照我想要的方式放置在<h3>標簽中)。有人可以幫助我進一步進行已經進行的調整嗎?
查看完整描述

1 回答

?
偶然的你

TA貢獻1841條經驗 獲得超3個贊

在 foreach 循環中,您可以將值存儲在變量中,而不是打印(回顯)。


在 foreach 之后,您可以打印變量


function filter_woocommerce_customer_available_downloads($downloads, $customer_id) { 

    // Manipulate download data here, this example we'll get the first 5 downloads in the array

    // $downloads = array_slice($downloads, 0, 5);

    // Sorting the array by Order Ids in DESC order

    arsort($downloads); 


    // Return first five downloads

    return $downloads;

}

add_filter( 'woocommerce_customer_available_downloads', 'filter_woocommerce_customer_available_downloads', 10, 2 );


/**

 * Group Downloadable products by product ID

 *

 * @param array $downloads

 * @return array

 */

function prefix_group_downloadable_products( array $downloads ) {

    $unique_downloads = [];


    foreach ($downloads as $download ) {

        $list = [

            'download_url' => $download['download_url'],

            'file_name'    => $download['file']['name'],

            'orderid'      => $download['order_id']

        ];


        if ( array_key_exists( $download['product_id'], $unique_downloads ) ) {

            $unique_downloads[ $download['product_id'] ]['list'][] = $list;

            continue;

        }


        $data = $download;

        $data['list'] = [ $list ];

        $unique_downloads[ $download['product_id'] ] = $data;

    }


    return $unique_downloads;

}

add_filter( 'woocommerce_customer_get_downloadable_products', 'prefix_group_downloadable_products', 10, 1 );


/**

 * Show number list of downloadable files for group product

 *

 * @param array $download

 * @return void

 */

function prefix_downloads_column_download_file( array $download ) {

    $lists = $download['list'];


    // Sorting the array by Order Ids in DESC order

    arsort($lists); 


    if ( empty( $lists ) ) {

        _e( 'No Download Files', 'storefront' );

        return;

    }


    // Set variable

    $li = '';


    foreach ( $lists as $list ) {

        // Get $order object from order ID 

        $order = wc_get_order( $list['orderid']  );


        $order_date = $order->get_date_completed();


        // Append to

        $li .= '<li><a href="' . esc_url( $list['download_url'] ) . '" class="woocommerce-MyAccount-downloads-file">' . esc_html( $list['file_name'] ) . '</a></li>';

    }


    echo '<ul class="charliesub">';

    echo '<li class="accordion">';

    echo '<h3>' .  $order_date . '</h3>';

    echo '<div>';

    echo '<ol>';


    echo $li;


    echo '</ol>';

    echo '</div>';

    echo '</li>';

    echo '</ul>';

}

add_action( 'woocommerce_account_downloads_column_download-file', 'prefix_downloads_column_download_file' );


查看完整回答
反對 回復 2022-11-04
  • 1 回答
  • 0 關注
  • 158 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號