Codexta_Connect::site_uuid(), 'origin' => Codexta_Connect::base_origin(), 'token' => Codexta_Token::url(), // What the page is about: on a product page the chat opens with that product tagged ("Asking about: ..."). 'context' => self::page_context(), ); wp_enqueue_script( 'codexta-widget-init', plugins_url( 'assets/js/codexta-widget-init.js', CODEXTA_ASSISTANT_FILE ), array( 'codexta-widget' ), CODEXTA_ASSISTANT_VERSION, true ); wp_add_inline_script( 'codexta-widget-init', 'window.codextaWoo = ' . wp_json_encode( $config ) . ';', 'before' ); } /** * What this page is about, for the chat to tag on the message box: the product of a single-product page, else null. * * @return array|null */ private static function page_context() { if ( ! function_exists( 'is_product' ) || ! is_product() ) { return null; } $product = wc_get_product( get_queried_object_id() ); if ( ! $product ) { return null; } return array( 'kind' => 'product', 'id' => (string) $product->get_id(), 'name' => wp_strip_all_tags( $product->get_name() ), ); } }