File tree Expand file tree Collapse file tree 1 file changed +43
-29
lines changed Expand file tree Collapse file tree 1 file changed +43
-29
lines changed Original file line number Diff line number Diff line change @@ -186,37 +186,51 @@ public function load_checkout_permalink_template( $template ) {
186186 );
187187 }
188188 }
189-
189+ $ use_iframe = ( bool ) apply_filters ( ' facebook_commerce_checkout_use_iframe ' , false );
190190 $ checkout_url = wc_get_checkout_url ();
191- echo '<!DOCTYPE html>
192- <html lang="en">
193- <head>
194- <meta charset="UTF-8">
195- <meta name="viewport" content="width=device-width, initial-scale=1">
196- <title>Checkout</title>
197- <style>
198- body, html {
199- margin: 0;
200- padding: 0;
201- height: 100%;
202- overflow: hidden;
203- }
204- iframe {
205- width: 100%;
206- height: 100vh;
207- border: none;
208- display: block;
209- max-width: 100%;
210- max-height: 100%;
211- box-sizing: border-box;
212- }
213- </style>
214- </head>
215- <body>
216- <iframe src=" ' . esc_url ( $ checkout_url ) . '"></iframe>
217- </body>
218- </html> ' ;
191+ if ( $ use_iframe ) {
192+ echo '<!DOCTYPE html>
193+ <html lang="en">
194+ <head>
195+ <meta charset="UTF-8">
196+ <meta name="viewport" content="width=device-width, initial-scale=1">
197+ <title>Checkout</title>
198+ <style>
199+ body, html {
200+ margin: 0;
201+ padding: 0;
202+ height: 100%;
203+ overflow: hidden;
204+ }
205+ iframe {
206+ width: 100%;
207+ height: 100vh;
208+ border: none;
209+ display: block;
210+ max-width: 100%;
211+ max-height: 100%;
212+ box-sizing: border-box;
213+ }
214+ </style>
215+ </head>
216+ <body>
217+ <iframe src=" ' . esc_url ( $ checkout_url ) . '"></iframe>
218+ </body>
219+ </html> ' ;
220+
221+ exit ;
222+ }
223+ if ( ! headers_sent () ) {
224+ wp_safe_redirect ( esc_url_raw ( $ checkout_url ) );
225+ exit ;
226+ }
219227
228+ // Fallback when headers already sent: force top-level navigation via JS
229+ echo '<!doctype html><html><head><meta charset="utf-8"><title> ' . esc_html__ ( 'Redirecting... ' , 'facebook-for-woocommerce ' ) . '</title></head><body> ' ;
230+ echo '<script> ' ;
231+ echo 'try{ top.location.replace( ' . wp_json_encode ( $ checkout_url ) . '); }catch(e){ window.location.replace( ' . wp_json_encode ( $ checkout_url ) . '); } ' ;
232+ echo '</script> ' ;
233+ echo '</body></html> ' ;
220234 exit ;
221235 }
222236
You can’t perform that action at this time.
0 commit comments