namespace Automattic\WooCommerce\Blocks\BlockTypes\OrderConfirmation; use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils; class Downloads extends AbstractOrderConfirmationBlock { protected $block_name = 'order-confirmation-downloads'; protected function render_content( $order, $permission = false, $attributes = [], $content = '' ) { $show_downloads = $order && $order->has_downloadable_item() && $order->is_download_permitted(); $downloads = $order ? $order->get_downloadable_items() : []; if ( ! $permission || ! $show_downloads ) { return $this->render_content_fallback(); } $classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, [ 'border_color', 'border_radius', 'border_width', 'border_style', 'background_color', 'text_color' ] ); return '
' . $this->render_order_downloads_column_headers() . '
' . $this->render_order_downloads( $order, $downloads ) . '
'; } protected function get_inline_styles( array $attributes ) { $link_classes_and_styles = StyleAttributesUtils::get_link_color_class_and_style( $attributes ); $link_hover_classes_and_styles = StyleAttributesUtils::get_link_hover_color_class_and_style( $attributes ); $border_classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, [ 'border_color', 'border_radius', 'border_width', 'border_style' ] ); return ' .wc-block-order-confirmation-downloads a {' . $link_classes_and_styles['style'] . '} .wc-block-order-confirmation-downloads a:hover, .wc-block-order-confirmation-downloads a:focus {' . $link_hover_classes_and_styles['style'] . '} .wc-block-order-confirmation-downloads {' . $border_classes_and_styles['styles'] . '} .wc-block-order-confirmation-downloads__headers, .wc-block-order-confirmation-downloads__body {' . $border_classes_and_styles['styles'] . '} '; } protected function enqueue_assets( array $attributes, $content, $block ) { parent::enqueue_assets( $attributes, $content, $block ); $styles = $this->get_inline_styles( $attributes ); wp_add_inline_style( 'wc-blocks-style', $styles ); } protected function render_order_downloads_column_headers() { $columns = wc_get_account_downloads_columns(); $return = ''; foreach ( $columns as $column_id => $column_name ) { $return .= '
' . esc_html( $column_name ) . '
'; } return $return; } protected function render_order_downloads( $order, $downloads ) { $return = ''; foreach ( $downloads as $download ) { $return .= '
' . $this->render_order_download_row( $download ) . '
'; } return $return; } protected function render_order_download_row( $download ) { $return = ''; foreach ( wc_get_account_downloads_columns() as $column_id => $column_name ) { $return .= '
'; if ( has_action( 'woocommerce_account_downloads_column_' . $column_id ) ) { $return .= $this->get_hook_content( 'woocommerce_account_downloads_column_' . $column_id, [ $download ] ); } else { switch ( $column_id ) { case 'download-product': if ( $download['product_url'] ) { $return .= '' . esc_html( $download['product_name'] ) . ''; } else { $return .= esc_html( $download['product_name'] ); } break; case 'download-file': $return .= '' . esc_html( $download['download_name'] ) . ''; break; case 'download-remaining': $return .= is_numeric( $download['downloads_remaining'] ) ? esc_html( $download['downloads_remaining'] ) : esc_html__( '∞', 'woocommerce' ); break; case 'download-expires': if ( ! empty( $download['access_expires'] ) ) { $return .= ''; } else { $return .= esc_html__( 'Never', 'woocommerce' ); } break; } } $return .= '
'; } return $return; } }