Show order ID and order date in WooCommerce My Account download page.
P粉330232096
P粉330232096 2023-07-27 13:10:51
0
1
364

我想在“我的账户”下载页面中显示订单ID、订单日期和产品图片。

add_filter( 'woocommerce_account_downloads_column_download-product', 'display_product_image_on_account_downloads' ); function display_product_image_on_account_downloads( $download ) { // Targeting view order pages only if ( ! is_wc_endpoint_url( 'downloads' ) ) return; if ( $download['product_id'] > 0 ) { $product = wc_get_product( $download['product_id'] ); $image = $product->get_image( array(324, 194) ); // The product image $order_id = $order->get_id(); // The order id if ( $download['product_url'] ) { echo $image . '' . esc_html( $download['product_name'] ) . ''; echo '

' . esc_html( $order_id ) . '

'; echo '

' . esc_html( wc_format_datetime( $order->get_date_created() ) ) . '

'; } else { echo $image . esc_html( $download['product_name'] ); } } }

产品图片已显示,但订单ID和订单日期未正确显示。有没有办法实现这个?谢谢。

P粉330232096
P粉330232096

reply all (1)
P粉903969231

I checked your code carefully and found some problems in it. So you can use the following version:

add_filter( 'woocommerce_account_downloads_column_download-product', 'display_product_image_order_info_on_account_downloads', 10, 2 ); function display_product_image_order_info_on_account_downloads( $download, $item ) { // Targeting view order pages only if ( ! is_wc_endpoint_url( 'downloads' ) ) return; if ( $download['product_id'] > 0 ) { $product = wc_get_product( $download['product_id'] ); $image = $product->get_image( array( 324, 194 ) ); // The product image $order_id = $item->get_order_id(); // Get the order ID from the $item object $order_date = $item->get_order()->get_date_created(); // Get the order date from the $item object if ( $download['product_url'] ) { echo $image . '' . esc_html( $download['product_name'] ) . ''; echo '

' . esc_html( $order_id ) . '

'; echo '

' . esc_html( wc_format_datetime( $order_date ) ) . '

'; } else { echo $image . esc_html( $download['product_name'] ); } } }

You can add this to your child theme’s functions.php file.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!