javascript - 如何在 WordPress 页面加载时加载 woocommerce get_session_cookie?

标签 javascript php jquery html wordpress

我正在 WordPress 中查看订单,但没有刷新页面。

没有页面刷新的单页订单的要求之一是初始化 woocommerce get_session_cookie()。

get_session_cookie() 可在 class-wc-handler.php 文件中找到,它是一个名为 class WC_Session_Handler extends WC_Session {}

的类
function get_my_wc_session_cookie() {
    WC_Session_Handler::get_session_cookie();
}

add_action('init', 'get_my_wc_session_cookie');

我在 functions.php 中添加了函数 get_session_cookie() 并将其挂接到“init”

但是提示错误:

Fatal error: Using $this when not in object context in C:\XamppDev\htdocs\mywebsite\wp-content\plugins\woocommerce\includes\class-wc-session-handler.php on line 170

您知道如何在页面加载时从 woocommerce 加载 get_session_cookie() 吗?

最佳答案

My friend try to set the cookie and then get cookie. sometimes at local system woocommerce cookie function desn't give appropriate result.
Please set a cookie by using the function below in functions.php --

<?php
add_action( 'init', 'setting_my_first_cookie' );

function setting_my_first_cookie() {
 setcookie( $v_username, $v_value, 30 * DAY_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
}
?>

Get the Cookie as below --

<?php

if(!isset($_COOKIE[$v_username])) {
  echo "The cookie: '" . $v_username . "' is not set.";
} else {
  echo "The cookie '" . $v_username . "' is set.";
  echo "Cookie is:  " . $_COOKIE[$v_username];
}

?>

关于javascript - 如何在 WordPress 页面加载时加载 woocommerce get_session_cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51630934/

相关文章:

javascript - 更改页面 JS/D3 上的元素位置

javascript - 使用 jQuery 在单击时更改当前 URL

php - 何时创建和删除 PayPal WebProfile 对象 (PHP)

javascript - knockout 类型错误 : m. apply is not a function

jquery - jquery如何在上传前预览图片

javascript - jQuery Plugin Isotope 没有正确地重新排列项目

java - Web app需要与串口通信

javascript - jQuery CSS 属性不适用

javascript - Ajax 数据库插入不起作用

php - wp_register_style() 和 wp_enqueue_style 的区别