duancao2082 2015-09-21 08:11
浏览 50

WooCommerce中的“SyntaxError:意外的令牌<”?

I am getting this error when I changed my woocommerce-2.3.13 version to woocommerce-2.4.6:

WooCommerce: SyntaxError: Unexpected token <

As per my knowledge, when i am adding script tag(< script>) on php file, the open script tag < giving errors, it means it is not reading the script tag.

I added my plugin(on php file) to connect checkout process with payment gateway to redirect to get bank list page. This error is coming when I try to redirect using JavaScript. Redirect function header("location:$url") is not working so i am using JavaScript.

?>
<script type='text/javascript'>
   window.location.href="<?php  echo $url; ?>";
</script >
<?

I tried

define('WP_DEBUG', false);error_reporting(0);@ini_set('display_errors', 0);

but I am getting the same errors.

  • 写回答

1条回答 默认 最新

  • doumei7420 2017-02-24 20:51
    关注

    When the WooCommerce checkout is processed it requires that gateways return an array (which is then converted into JSON) telling the checkout whether or not it was successful. It’s been this way since v1.

    In 2.4+ this was made more strict in that the response must be valid JSON. Anything else in the response (such as HTML, notices or whitespace) will invalidate this JSON and you may see an error along the lines of:

    SyntaxError: Unexpected token
    

    See a way to debug it in this blog post https://mikejolley.com/2015/11/12/debugging-unexpected-token-in-woocommerce-2-4/

    I followed all the instructions on that blog post, disabled all the plug-ins, and it turned out that the JSON response was sending back an error instead of correctly formatted JSON. My response was:

    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_SSLVERSION -     assumed 'CURLOPT_SSLVERSION' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_USERAGENT - assumed 'CURLOPT_USERAGENT' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_SSL_VERIFYHOST - assumed 'CURLOPT_SSL_VERIFYHOST' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Notice</b>:  Use of undefined constant CURLOPT_SSL_CIPHER_LIST - assumed 'CURLOPT_SSL_CIPHER_LIST' in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php</b> on line <b>57</b><br />
    <br />
    <b>Fatal error</b>:  Call to undefined function PayPal\Core\curl_version() in <b>/var/www/html/wp-content/plugins/woocommerce-product-vendors/includes/gateways/paypal-php-sdk/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConfig.php</b> on line <b>65</b><br />
    

    In my case, it was a problem with WooCommerce PayPal Pro payment gateway and WooCommerce Product Vendors because cURL was not installed by default on my DigitalOcean server. With WooCommerce Product Vendors, every time a customer places an order, the vendor gets paid commission with PayPal Mass Payments. In order for PayPal Mass Payment to work, you have to make sure that you enable Mass Payments on your PayPal account and to make sure the cURL is installed on your server.

    As soon as I installed the cURL, it worked. Here is how to install cURL on DigitalOcean https://www.digitalocean.com/community/questions/curl-is-not-installed-in-your-php-installation

    Hope this helps someone out there.

    评论

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程