How to call WC()->session in a hook action?
I’ve got a custom WP plugin that handles data from WC and send it via form-7. This has always worked fine until some time and updates ago. I’m trying to fix it and it occurs to me that the WC->session is not available in the:
wpcf7_before_send_mail()
So I read in the answer of ClemC on this question (What’s the difference between WC() and $woocommerce) and I quote:
About your errors, you got them because $woocommerce->session has not been set. WC initializes WC_Session_Handler only on frontend or CRON requests. Choose your action hook accordingly.
Ok this makes sense. But how can I force the WC() object to load like it’s on frontend and therefore the WC()->session is not empty anymore?
Leave an answer