cart ) return; $ref = wp_get_referer(); if ( ! $ref || strpos( $ref, admin_url() ) !== 0 ) return; if ( WC()->cart->is_empty() ) return; add_action( 'wp_footer', [ __CLASS__, 'render_modal_html' ] ); } public static function enqueue_assets() { if ( ! self::is_enabled() ) return; if ( ! is_user_logged_in() || ! current_user_can('manage_woocommerce') ) return; wp_enqueue_style( 'aisp-safe-admin', AISP_OTOOLS_URL . 'assets/css/safe-admin-checkout.css', [], AISP_OTOOLS_VERSION ); wp_enqueue_script( 'aisp-safe-admin', AISP_OTOOLS_URL . 'assets/js/safe-admin-checkout.js', [], AISP_OTOOLS_VERSION, true ); wp_localize_script( 'aisp-safe-admin', 'aispOtoolsSafeCheckout', [ 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( self::NONCE_KEY ), 'confirm' => __( 'Create a new order?', 'aisp-order-tools-for-woocommerce' ), 'text' => __( 'This cart already contains items. Would you like to clear it to start a fresh order?', 'aisp-order-tools-for-woocommerce' ), 'yes' => __( 'Yes — Reset Cart', 'aisp-order-tools-for-woocommerce' ), 'no' => __( 'No — Keep Current Cart', 'aisp-order-tools-for-woocommerce' ), ] ); } public static function render_modal_html() { echo '
'; } public static function ajax_reset_cart() { if ( ! current_user_can('manage_woocommerce') ) wp_die(); if ( empty($_POST['nonce']) || ! wp_verify_nonce( sanitize_text_field( wp_unslash($_POST['nonce']) ), self::NONCE_KEY ) ) { wp_die(); } $wc = WC(); $wc->cart->empty_cart( true ); $wc->session->set( 'chosen_shipping_methods', [] ); $wc->session->set( 'shipping_for_package_0', [] ); wp_die('success'); } public static function disable_cart_shipping_for_admins( $needs ) { if ( current_user_can( 'manage_woocommerce' ) && is_cart() ) { return false; } return $needs; } public static function force_empty_shipping_fields( $value, $input ) { if ( current_user_can( 'manage_woocommerce' ) && str_starts_with( $input, 'shipping_' ) ) { return ''; } return $value; } }