diff --git a/plugins/woocommerce/changelog/add-show-downloads-hook b/plugins/woocommerce/changelog/add-show-downloads-hook new file mode 100644 index 00000000000..8d4b9e92c4f --- /dev/null +++ b/plugins/woocommerce/changelog/add-show-downloads-hook @@ -0,0 +1,4 @@ +Significance: minor +Type: add + +Adds new hook `woocommerce_order_downloads_table_show_downloads` to control rendering of the downloads table (classic templates only). diff --git a/plugins/woocommerce/includes/wc-template-functions.php b/plugins/woocommerce/includes/wc-template-functions.php index a4cbf70014e..d42d90c96f5 100644 --- a/plugins/woocommerce/includes/wc-template-functions.php +++ b/plugins/woocommerce/includes/wc-template-functions.php @@ -2723,10 +2723,30 @@ if ( ! function_exists( 'woocommerce_order_details_table' ) ) { return; } + $order = wc_get_order( $order_id ); + + if ( ! $order ) { + return; + } + wc_get_template( 'order/order-details.php', array( - 'order_id' => $order_id, + 'order_id' => $order_id, + /** + * Determines if the order downloads table should be shown (in the context of the order details + * template). + * + * By default, this is true if the order has at least one dowloadable items and download is permitted + * (which is partly determined by the order status). For special cases, though, this can be overridden + * and the downloads table can be forced to render (or forced not to render). + * + * @since 8.5.0 + * + * @param bool $show_downloads If the downloads table should be shown. + * @param WC_Order $order The related order. + */ + 'show_downloads' => apply_filters( 'woocommerce_order_downloads_table_show_downloads', ( $order->has_downloadable_item() && $order->is_download_permitted() ), $order ), ) ); } diff --git a/plugins/woocommerce/templates/order/order-details.php b/plugins/woocommerce/templates/order/order-details.php index 6713ceacda8..131d86b91c2 100644 --- a/plugins/woocommerce/templates/order/order-details.php +++ b/plugins/woocommerce/templates/order/order-details.php @@ -12,7 +12,9 @@ * * @see https://woo.com/document/template-structure/ * @package WooCommerce\Templates - * @version 7.8.0 + * @version 8.5.0 + * + * @var bool $show_downloads Controls whether the downloads table should be rendered. */ defined( 'ABSPATH' ) || exit; @@ -27,7 +29,6 @@ $order_items = $order->get_items( apply_filters( 'woocommerce_purchase $show_purchase_note = $order->has_status( apply_filters( 'woocommerce_purchase_note_order_statuses', array( 'completed', 'processing' ) ) ); $show_customer_details = is_user_logged_in() && $order->get_user_id() === get_current_user_id(); $downloads = $order->get_downloadable_items(); -$show_downloads = $order->has_downloadable_item() && $order->is_download_permitted(); if ( $show_downloads ) { wc_get_template(