id( 'customer-downloads-preview' ) ->with( [ 'allLink' => add_query_arg( [ 'tab' => $this->getTab(), 'model' => 'download', 'action' => 'index', ], remove_query_arg( array_keys( $_GET ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended ), 'requestNonce' => wp_create_nonce( 'customer-download' ), 'isCustomer' => User::current()->isCustomer(), 'query' => [ 'customer_ids' => array_values( User::current()->customerIds() ), 'page' => 1, 'per_page' => 10, ], ] )->render( "" . ( $attributes['title'] ?? __( 'Downloads', 'surecart' ) ) . '' ) ); } /** * Index. */ public function index( $attributes = [] ) { if ( ! is_user_logged_in() ) { return; } ob_start(); ?> id( 'customer-downloads-preview' ) ->with( [ 'requestNonce' => wp_create_nonce( 'customer-download' ), 'isCustomer' => User::current()->isCustomer(), 'query' => [ 'customer_ids' => array_values( User::current()->customerIds() ), 'page' => 1, 'per_page' => 10, ], ] )->render( "" . ( $attributes['title'] ?? __( 'Downloads', 'surecart' ) ) . '' ) ); ?> find( $this->getId() ); if ( empty( $purchase->customer->id ) || ! User::current()->hasCustomerId( $purchase->customer->id ) ) { return null; } // Only scope to the variant when it has its own files; otherwise fall back to product-level downloads. $variant = $purchase->variant ?? null; $active_variant_downloads = array_filter( (array) ( $variant->downloads->data ?? [] ), fn( $download ) => empty( $download->archived ) ); $has_variant_downloads = ! empty( $variant->downloads_enabled ) && ! empty( $active_variant_downloads ); ob_start(); ?> id( 'customer-purchase' ) ->with( [ 'heading' => __( 'Downloads', 'surecart' ), 'customerId' => $purchase->customer->id ?? '', 'productId' => $purchase->product->id ?? '', 'variantId' => $has_variant_downloads ? ( $variant->id ?? '' ) : '', ] )->render() ); ?> license ) : echo wp_kses_post( Component::tag( 'sc-licenses-list' ) ->id( 'customer-licenses' ) ->with( [ 'heading' => __( 'License Keys', 'surecart' ), 'licenses' => [ $purchase->license ], ] )->render() ); endif; ?>