I want to display the order ID, order date and product image in the My Account download page.
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 . '<a href="' . esc_url( $download['product_url'] ) . '">' . esc_html( $download['product_name'] ) . '</a>';
echo '<p>' . esc_html( $order_id ) . '</p>';
echo '<p>' . esc_html( wc_format_datetime( $order->get_date_created() ) ) . '</p>';
} else {
echo $image . esc_html( $download['product_name'] );
}
}
}
The product image is displayed, but the order ID and order date do not display properly.
Is there any way of achieving this? Thanks.
2
Answers
I carefully check your code and realized it has some problems. So you can use these version:
You can use it on your function.php on your child-theme.
First,
woocommerce_account_downloads_column_download-product
is an action hook and the variable$order
is not defined in your code.Use instead this revisited code version:
It should work now.