/** * ==================================================================== * 3) Hantera PDF-endpoint: om URL innehåller receipt_pdf & order_key. * ==================================================================== */ add_action( 'template_redirect', function() { global $wp_query; // Hämta order_id ur query_vars (t.ex. ?receipt_pdf=123) $order_id = isset( $wp_query->query_vars['receipt_pdf'] ) ? intval( $wp_query->query_vars['receipt_pdf'] ) : 0; // Hämta order_key från GET-parametern $order_key = isset( $_GET['order_key'] ) ? sanitize_text_field( wp_unslash( $_GET['order_key'] ) ) : ''; // Om receipt_pdf finns men order_key är tom (saknas) if ( $order_id > 0 && empty( $order_key ) ) { wp_die( 'Fel: order_key saknas. Du måste ange både receipt_pdf och order_key i URL:en.', 'Ogiltigt anrop', array( 'response' => 400 ) ); } // Om inget order_id är skickat alls (alltså inte vår PDF-endpoint), låt WP fortsätta som vanligt if ( $order_id <= 0 ) { return; } // Om vi har ett order_id och ett order_key → hämta ordern $order = wc_get_order( $order_id ); if ( ! $order ) { wp_die( 'Fel: ogiltigt order-ID.', 'PDF-Error', array( 'response' => 404 ) ); } // Kontrollera att order_key matchar if ( $order->get_order_key() !== $order_key ) { wp_die( 'Fel: order_key är ogiltig eller matchar inte den här ordern.', '403 Forbidden', array( 'response' => 403 ) ); } // ---------------------------- // Härifrån är order_key giltigt → generera PDF // ---------------------------- ob_start(); ?> Kvitto för order # Warning: Undefined variable $order in /customers/6/f/3/halalexpress.se/httpd.www/wp-content/plugins/yith-sms-pdf-receipt/yith-sms-pdf-receipt.php on line 52 Fatal error: Uncaught Error: Call to a member function get_order_number() on null in /customers/6/f/3/halalexpress.se/httpd.www/wp-content/plugins/yith-sms-pdf-receipt/yith-sms-pdf-receipt.php:52 Stack trace: #0 /customers/6/f/3/halalexpress.se/httpd.www/wp-settings.php(545): include_once() #1 /customers/6/f/3/halalexpress.se/httpd.www/wp-config.php(127): require_once('/customers/6/f/...') #2 /customers/6/f/3/halalexpress.se/httpd.www/wp-load.php(50): require_once('/customers/6/f/...') #3 /customers/6/f/3/halalexpress.se/httpd.www/wp-blog-header.php(13): require_once('/customers/6/f/...') #4 /customers/6/f/3/halalexpress.se/httpd.www/index.php(17): require('/customers/6/f/...') #5 {main} thrown in /customers/6/f/3/halalexpress.se/httpd.www/wp-content/plugins/yith-sms-pdf-receipt/yith-sms-pdf-receipt.php on line 52