exclusions = $exclusions; add_action( 'init', array( $this, 'register_woocommerce_exclusions' ) ); add_filter( 'awvb_excluded_scripts', array( $this, 'exclude_wc_scripts' ) ); } /** * Check if WooCommerce is installed and active. * * @return bool */ public static function is_active() { return class_exists( 'WooCommerce' ); } /** * Automatically protect WooCommerce sensitive endpoints from aggressive buffering. */ public function register_woocommerce_exclusions() { if ( ! self::is_active() ) { return; } if ( function_exists( 'wc_get_page_id' ) ) { $cart_id = wc_get_page_id( 'cart' ); $checkout_id = wc_get_page_id( 'checkout' ); $account_id = wc_get_page_id( 'myaccount' ); if ( $cart_id > 0 ) { $this->exclusions->add_exclusion( (string) wp_parse_url( get_permalink( $cart_id ), PHP_URL_PATH ) ); } if ( $checkout_id > 0 ) { $this->exclusions->add_exclusion( (string) wp_parse_url( get_permalink( $checkout_id ), PHP_URL_PATH ) ); } if ( $account_id > 0 ) { $this->exclusions->add_exclusion( (string) wp_parse_url( get_permalink( $account_id ), PHP_URL_PATH ) ); } } if ( isset( $_GET['wc-ajax'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->exclusions->add_exclusion( '*' ); } } /** * Exclude WooCommerce core interactive scripts from delay execution. * * @param array $scripts Array of script keywords/handles. * @return array */ public function exclude_wc_scripts( $scripts ) { if ( ! self::is_active() ) { return $scripts; } $wc_scripts = array( 'woocommerce', 'wc-checkout', 'wc-cart', 'wc-cart-fragments', 'wc-add-to-cart', 'selectWoo', 'select2', ); return array_merge( (array) $scripts, $wc_scripts ); } }