/** * PNP ULTIMATE MASTER SPEED OPTIMIZER - VERSION 6.0 * Features: A+ Grade, Instant Typing, PK Phone Validation, Celebration, Admin Safe. * NO DOUBLE CLICK FIX INCLUDED. */ /* ========================================================================== 1. CORE SPEED & ADMIN SAFETY (SMART HEARTBEAT) ========================================================================== */ add_action( 'init', function() { $is_privileged_user = current_user_can('manage_woocommerce') || current_user_can('manage_options'); $is_elementor = isset($_GET['elementor-preview']) || (isset($_GET['action']) && $_GET['action'] == 'elementor'); if ( is_admin() || $is_privileged_user || $is_elementor ) { remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); return; } wp_deregister_script('heartbeat'); remove_action( 'shutdown', 'wp_ob_end_flush_all', 1 ); }, 1); /* ========================================================================== 2. ASSET CLEANUP (VISITOR ONLY) ========================================================================== */ add_action( 'wp_enqueue_scripts', function() { if ( current_user_can('edit_posts') || isset($_GET['elementor-preview']) ) return; wp_dequeue_style( 'wp-block-library' ); wp_dequeue_style( 'classic-theme-styles' ); if ( is_front_page() ) { wp_dequeue_script( 'contact-form-7' ); wp_dequeue_script( 'sbr-scripts' ); } if ( is_checkout() || is_order_received_page() ) { $killers = ['wc-cart-fragments','xt-woofc-js','sbi_scripts','cffscripts','trustindex-js','google-listings-and-ads']; foreach ( $killers as $h ) { wp_dequeue_script( $h ); wp_deregister_script( $h ); } } }, 9999); /* ========================================================================== 3. INSTANT TYPING & PK PHONE VALIDATION ========================================================================== */ add_filter( 'woocommerce_checkout_fields', function( $fields ) { if ( is_admin() ) return $fields; $instant = ['billing_first_name', 'billing_last_name', 'billing_email', 'billing_phone']; foreach ( $instant as $f ) { if ( isset( $fields['billing'][$f]['class'] ) ) { $fields['billing'][$f]['class'] = array_diff($fields['billing'][$f]['class'], ['address-field', 'update_totals_on_change']); } } return $fields; }, 999); add_action('woocommerce_checkout_process', function() { if (isset($_POST['billing_phone'])) { $phone = str_replace([' ', '-', '+'], '', $_POST['billing_phone']); if ( !preg_match('/^03[0-9]{9}$/', $phone) ) { wc_add_notice( 'Invalid Phone: Use 11 digits starting with 03 (e.g. 03001234567).', 'error' ); } } }); /* ========================================================================== 4. FRONT-END: CHECKER, CELEBRATION, & DOUBLE-CLICK FIX ========================================================================== */ add_action( 'wp_footer', function() { if ( ! is_checkout() || current_user_can('edit_posts') ) return; ?>
Processing Order... ✨
Thank you for choosing Pins & Pearls.
'; } }, 1 );