Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
Javascript and Wordpress Uncaught SyntaxError using wp_enqueue_script on single product page of woocommerce

I'm no good at javascript but I think this code is right because it is just copy and paste from Zopim website and it was working before I tried to use their widget in a different approach.

functions.php

<?php
if ( is_product()) {
    function wpa_enqueue_scripts() {
        wp_enqueue_script( 'wpa-main-js', get_theme_file_uri( 'js/zopim.js' ), [], null, true );
    }

    add_action( 'wp_enqueue_scripts', 'wpa_enqueue_scripts', 100 );
}

I am having another issue with the code above. I can't get the script file to load on products page. It only work if I remove the if conditional.

zopim.js

<script type="text/javascript">
window.$zopim||(function(d,s){var z=$zopim=function(c){z._.push(c)},$=z.s=
d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
_.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute("charset","utf-8");
$.src="https://v2.zopim.com/?3eGZHNIx48cV45BpV2eeQ5nlDBvLzS0P";z.t=+new Date;$.
type="text/javascript";e.parentNode.insertBefore($,e)})(document,"script");
</script>

This script give me this error:

"Uncaught SyntaxError: expected expression, got '<'" and I have no idea why.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

"It only work if I remove the if conditional."

  1. I'd write the if statement inside the wp_enqueue_scripts hook. Like so:
add_action( 'wp_enqueue_scripts', 'wpa_enqueue_scripts');

function wpa_enqueue_scripts()
{
    if ( is_product()) 
    {
        wp_enqueue_script( 'wpa-main-js', get_theme_file_uri( 'js/zopim.js' ), [], null, true );
    }
} 

"This script give me this error "Uncaught SyntaxError: expected expression, got '<'" and I have no idea why."

  1. You don't need script tags in your javascript file. So you could go ahead and remove <script type="text/javascript"> and </script>.

Let me know if you could get it to work.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda