Pre-fill Woocommerce checkout fields with Url variable before session created

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 21:16:11

You can use Pre-fill Woocommerce checkout fields with Url variables saved in session answer code and initialize a session cookie before add to cart action, using the following:

add_action( 'woocommerce_init', 'initiate_customer_session_cookie' )
function initiate_customer_session_cookie(){
    // Ensure that Woocommerce session cookie is initiated
    if ( ! WC()->session->has_session() ) 
        WC()->session->set_customer_session_cookie( true );
}

Code goes in function.php file of your active child theme (or active theme). Tested and works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!