get_injection_mode() || ( self::MODE_PRODUCT_PAGES === $this->get_injection_mode() && function_exists( 'is_product' ) && is_product() ); } /** * Determine whether the merchant selected manual placement. */ public function should_load_runtime() { return self::MODE_COMPONENTS_ONLY === $this->get_injection_mode(); } /** * Load the local consent adapter on relevant storefront pages. */ public function enqueue_frontend_scripts() { if ( Selectika_Connection::active( 'tracking' ) || Selectika_Connection::active( 'orders' ) || $this->should_load_full_script() || $this->is_shortcode_or_block_on_page() ) { $this->enqueue_components_runtime(); } } /** * Enqueue public configuration without session data or credentials. */ public function enqueue_components_runtime() { if ( ! Selectika_Connection::active() || wp_script_is( 'selectika-commerce', 'enqueued' ) ) { return; } $c = Selectika_Connection::get(); $product = function_exists( 'is_product' ) && is_product() ? wc_get_product( get_queried_object_id() ) : null; $page = function_exists( 'is_order_received_page' ) && is_order_received_page() ? 'order_received' : ( function_exists( 'is_checkout' ) && is_checkout() ? 'checkout' : ( function_exists( 'is_cart' ) && is_cart() ? 'cart' : ( $product ? 'product' : 'page' ) ) ); $config = array( 'schemaVersion' => 1, 'retailerName' => $c['retailer'], 'siteId' => $c['site_id'], 'generation' => $c['generation'], 'manualPlacement' => ! $this->should_load_full_script(), 'widgetsEnabled' => Selectika_Connection::active( 'widgets' ), 'trackingEnabled' => Selectika_Connection::active( 'tracking' ), 'serverOrdersEnabled' => Selectika_Connection::active( 'orders' ), 'publisherId' => $c['publisher_id'], 'pageType' => $page, 'currency' => function_exists( 'get_woocommerce_currency' ) ? get_woocommerce_currency() : '', 'contextUrl' => function_exists( 'WC' ) ? add_query_arg( 'wc-ajax', 'selectika_context', home_url( '/' ) ) : null, 'cartApiUrl' => function_exists( 'WC' ) ? rest_url( 'wc/store/v1/cart/add-item' ) : null, 'product' => $product ? Selectika_Events::item( $product, 1 ) : null, ); wp_enqueue_script( 'selectika-commerce', SELECTIKA_PLUGIN_URL . 'assets/commerce.js', array(), SELECTIKA_VERSION, true ); wp_add_inline_script( 'selectika-commerce', 'window.SelectikaCommerceConfig=' . wp_json_encode( $config, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ) . ';', 'before' ); } /** * Detect existing shortcode or block placements on the queried page. */ public function is_shortcode_or_block_on_page() { global $post; return $post && is_singular() && ( has_shortcode( $post->post_content, 'selectika' ) || has_block( 'selectika/widget', $post ) ); } }