我正在 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/