enqueueSideCart(); } if ($checkoutPage) { $this->enqueueCheckout(); } } private function enqueueSideCart(): void { $asset = $this->assetMetadata('frontend/side-cart.asset.php'); wp_enqueue_script( 'arrayfunnel-side-cart', (string) Config::get('plugin.public_url') . 'build/frontend/side-cart.js', $asset['dependencies'], $asset['version'], true ); wp_localize_script('arrayfunnel-side-cart', 'arrayfunnelCart', [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('arrayfunnel_cart_nonce'), 'currency' => [ 'symbol' => get_woocommerce_currency_symbol(), 'code' => get_woocommerce_currency(), 'position' => get_option('woocommerce_currency_pos'), ], 'openMode' => get_option('arrayfunnel_side_cart_open_mode', 'always'), 'i18n' => [ 'emptyCart' => __('Your cart is empty', 'arrayfunnel'), 'continueShopping' => __('Continue Shopping', 'arrayfunnel'), 'remove' => __('Remove', 'arrayfunnel'), 'freeShipping' => __("You've unlocked FREE shipping!", 'arrayfunnel'), 'freeShippingUnlocked' => __("You've unlocked FREE shipping!", 'arrayfunnel'), 'freeShippingUnlockedShort' => __('Unlocked', 'arrayfunnel'), 'freeShippingPending' => __('Add more to unlock FREE shipping', 'arrayfunnel'), 'leftLabel' => __('left', 'arrayfunnel'), 'couponApplied' => __('Coupon applied!', 'arrayfunnel'), 'couponError' => __('Invalid coupon code.', 'arrayfunnel'), ], ]); } private function enqueueCheckout(): void { $asset = $this->assetMetadata('frontend/checkout.asset.php'); wp_enqueue_script( 'arrayfunnel-checkout', (string) Config::get('plugin.public_url') . 'build/frontend/checkout.js', $asset['dependencies'], $asset['version'], true ); wp_localize_script('arrayfunnel-checkout', 'arrayfunnelCheckout', [ 'ajaxUrl' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('arrayfunnel_checkout_nonce'), 'countdownMins' => (int) get_option('arrayfunnel_checkout_countdown_mins', 15), // This bundle also owns countdown and cart capture, which remain available // when the order-bump module is disabled. 'orderBumpsEnabled' => \ArrayFunnel\Features\OrderBumps\Services\OrderBump::isEnabled(), ]); } /** * Read the dependency and version metadata generated for a built asset. * * @param string $relativePath Path to the metadata file, relative to the build directory. * * @return array{dependencies: string[], version: string} */ private function assetMetadata(string $relativePath): array { $metadataFile = (string) Config::get('plugin.public_path') . 'build/' . $relativePath; $metadata = is_readable($metadataFile) ? require $metadataFile : null; if (!is_array($metadata)) { return ['dependencies' => [], 'version' => ARRAYFUNNEL_VERSION]; } return [ 'dependencies' => isset($metadata['dependencies']) && is_array($metadata['dependencies']) ? $metadata['dependencies'] : [], 'version' => empty($metadata['version']) ? ARRAYFUNNEL_VERSION : (string) $metadata['version'], ]; } }