最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Why isn't working WooCommerce session inside shortcode?

programmeradmin2浏览0评论

Hope you're doing great! I am trying to print the WC()->session->get inside a shortcode but getting error , bellow is my code and error

function set_session(){

    global $woocommerce;
    WC()->session->set( 'some_data_get' ,' some_data_get' );    

}
add_action( 'init', 'set_session' );

function show_session(){

   global $woocommerce;
   var_dump(  WC()->session->get( 'some_data_get' ) );

}
add_shortcode( 'show_session', 'show_session' );

do_shortcode('[show_session]');

here is error

Fatal error: Uncaught Error: Call to a member function get() on null in E:\OFFICE-SERVER\htdocs\aspw\wp-content\themes\twentynineteen\functions.php:335 
发布评论

评论列表(0)

  1. 暂无评论