'' === $value ? time() - DAY_IN_SECONDS : (int) $expires, 'path' => defined( 'COOKIEPATH' ) && COOKIEPATH ? COOKIEPATH : '/', 'domain' => defined( 'COOKIE_DOMAIN' ) && COOKIE_DOMAIN ? COOKIE_DOMAIN : '', 'secure' => is_ssl(), 'httponly' => false, 'samesite' => 'Lax', ) ); } /** * Whether this page can lead to a payment: product, cart, checkout and account pages. * * @return bool */ private static function is_shop_page() { $shop = ( function_exists( 'is_product' ) && is_product() ) || ( function_exists( 'is_cart' ) && is_cart() ) || ( function_exists( 'is_checkout' ) && is_checkout() ) || ( function_exists( 'is_account_page' ) && is_account_page() ); /** * Filters whether Brickmoat's storefront script loads on the current page. * * @param bool $shop True on product, cart, checkout and account pages. */ return (bool) apply_filters( 'brickmoat_load_storefront_script', $shop ); } /** * Loads the storefront script: small, deferred, and only where a payment can start. */ public static function assets() { if ( ! self::is_shop_page() ) { return; } $asset_file = BRICKMOAT_DIR . 'build/storefront.asset.php'; if ( ! is_readable( $asset_file ) ) { return; } $asset = require $asset_file; wp_enqueue_script( 'brickmoat-storefront', plugins_url( 'build/storefront.js', BRICKMOAT_FILE ), $asset['dependencies'], $asset['version'], array( 'strategy' => 'defer', 'in_footer' => true, ) ); $config = array( 'rest' => esc_url_raw( rest_url( 'brickmoat/v1/' ) ), 'loggedIn' => is_user_logged_in(), 'checkout' => ( function_exists( 'is_checkout' ) && is_checkout() ) || ( function_exists( 'is_add_payment_method_page' ) && is_add_payment_method_page() ), 'turnstile' => '' !== (string) Settings::value( 'turnstileSecret' ) ? (string) Settings::value( 'turnstileSiteKey' ) : '', 'i18n' => array( 'title' => __( 'One quick check', 'brickmoat' ), 'intro' => __( 'Please confirm you are a person, then place your order.', 'brickmoat' ), 'label' => __( 'I’m human', 'brickmoat' ), 'working' => __( 'Checking…', 'brickmoat' ), 'done' => __( 'Thank you. You can place your order now.', 'brickmoat' ), 'retrying' => __( 'Thank you. Placing your order…', 'brickmoat' ), 'failed' => __( 'That did not work. Please try again.', 'brickmoat' ), 'close' => __( 'Close', 'brickmoat' ), ), ); wp_add_inline_script( 'brickmoat-storefront', 'window.brickmoatStorefront = ' . wp_json_encode( $config ) . ';', 'before' ); // The block checkout sends its requests through wp.apiFetch; this adds the token to them. $blocks_file = BRICKMOAT_DIR . 'build/checkout-blocks.asset.php'; $has_blocks = ( function_exists( 'has_block' ) && ( has_block( 'woocommerce/checkout' ) || has_block( 'woocommerce/cart' ) ) ) || ( function_exists( 'is_checkout_pay_page' ) && is_checkout_pay_page() ); if ( $has_blocks && is_readable( $blocks_file ) ) { $blocks = require $blocks_file; wp_enqueue_script( 'brickmoat-checkout-blocks', plugins_url( 'build/checkout-blocks.js', BRICKMOAT_FILE ), array_unique( array_merge( $blocks['dependencies'], array( 'wp-api-fetch' ) ) ), $blocks['version'], array( 'in_footer' => true ) ); } } /** * Hidden fields on the classic checkout: the token, the pass, and a trap only bots fill in. */ public static function checkout_fields() { echo ''; echo '
'; } }