' . esc_html( Eligibility::message( 'disabled', 'withdrawal' ) ) . '

'; } $request = Access::request_from_query(); if ( $request ) { Access::no_cache(); return Portal::request_view( $request ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $order_id = isset( $_GET['rtkt_order'] ) ? absint( $_GET['rtkt_order'] ) : 0; if ( $order_id ) { Access::no_cache(); $order = Access::order_from_query(); if ( ! $order ) { // Logged-in owner without a key in the URL. $candidate = wc_get_order( $order_id ); $order = Access::can_use_order( $candidate ) ? $candidate : null; } if ( ! $order ) { return Template::render( 'portal/not-found.php' ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $key = isset( $_GET['rtkt_key'] ) ? sanitize_text_field( wp_unslash( $_GET['rtkt_key'] ) ) : ''; return self::order_flow( $order, $key ); } if ( Forms::$review && ! Forms::$review['order'] ) { return self::review( Forms::$review, null, '' ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $general = isset( $_GET['rtkt_general'] ) || ! is_user_logged_in(); if ( ! $general ) { Access::no_cache(); $orders = Eligibility::customer_orders( get_current_user_id(), 'withdrawal', 30 ); if ( $orders ) { return Template::render( 'portal/withdrawal-orders.php', array( 'notices' => Template::notices(), 'orders' => $orders, 'general_url' => add_query_arg( 'rtkt_general', '1' ), ) ); } } return Template::render( 'portal/withdrawal-form.php', array( 'notices' => Template::notices(), 'order' => null, 'key' => '', 'lines' => array(), 'old' => Forms::$old, 'user' => is_user_logged_in() ? wp_get_current_user() : null, 'check' => null, ) ); }, '

' . esc_html__( 'The withdrawal form is temporarily unavailable. Please email us your withdrawal instead; it is just as valid.', 'returnkit' ) . '

', 'withdrawal page' ); } /** * Withdrawal for a known order: the form, or the review step. * * @param \WC_Order $order Order. * @param string $key Order key (guest link) or ''. * @return string */ public static function order_flow( \WC_Order $order, $key ) { Assets::enqueue(); if ( Forms::$review && Forms::$review['order'] && Forms::$review['order']->get_id() === $order->get_id() ) { return self::review( Forms::$review, $order, $key ); } $check = Eligibility::check( $order, 'withdrawal' ); return Template::render( 'portal/withdrawal-form.php', array( 'notices' => Template::notices(), 'order' => $order, 'key' => $key, 'check' => $check, 'message' => $check['ok'] ? '' : Eligibility::message( $check['code'], 'withdrawal' ), 'lines' => $check['ok'] && Settings::get( 'withdrawal_items' ) ? Eligibility::items( $order, 'withdrawal' ) : array(), 'old' => Forms::$old, 'user' => null, 'existing' => Requests::query( array( 'order_id' => $order->get_id(), 'type' => 'withdrawal', ), 10 ), ) ); } /** * The review step with the "Confirm withdrawal" button. * * @param array $review Data from Forms. * @param \WC_Order|null $order Order. * @param string $key Order key or ''. * @return string */ private static function review( array $review, $order, $key ) { $items = array(); if ( $order && 'items' === $review['args']['scope'] ) { foreach ( Eligibility::items( $order, 'withdrawal' ) as $line ) { $qty = isset( $review['lines'][ $line['item_id'] ] ) ? (int) $review['lines'][ $line['item_id'] ]['qty'] : 0; if ( $qty > 0 ) { $items[] = array( 'item_id' => $line['item_id'], 'name' => $line['name'], 'qty' => min( $qty, $line['available'] ), ); } } } return Template::render( 'portal/withdrawal-review.php', array( 'notices' => Template::notices(), 'order' => $order, 'key' => $key, 'args' => $review['args'], 'items' => $items, ) ); } /** * [returnkit_withdrawal_button] – the "withdraw from contract here" link * for footers, menus and legal pages. * * @param array $atts label, class. * @return string */ public static function button( $atts = array() ) { $atts = shortcode_atts( array( 'label' => '', 'class' => '', ), $atts, 'returnkit_withdrawal_button' ); if ( ! Eligibility::enabled( 'withdrawal' ) ) { return ''; } $label = '' !== trim( $atts['label'] ) ? $atts['label'] : Settings::text( 'withdrawal_label' ); return '' . esc_html( $label ) . ''; } /** * Optional site-wide footer link. * * @return void */ public static function footer_link() { if ( ! Settings::get( 'withdrawal_in_footer' ) || ! Eligibility::enabled( 'withdrawal' ) || '' === Access::withdrawal_base() || is_admin() ) { return; } echo ''; } }