在联系表7上发送电子邮件之前,我想获取woocommerce购物车会话数据。我尝试了以下方法,但是以某种方式wocommerce购物车对象无法访问。
在这个示例中,我只是想计算购物车中的物品数量。
add_action( 'wpcf7_before_send_mail', 'product_enquiry' );
function product_enquiry($WPCF7_ContactForm)
{
//here is the place i want to get woocommerce cart items data
$cart_contents_count = count(WC()->cart->get_cart()); //it sound like not working
$wpcf7 = WPCF7_ContactForm :: get_current() ;
$submission = WPCF7_Submission :: get_instance() ;
$formId = $wpcf7->id();
if ($submission && $formId == 6)
{
$posted_data = $submission->get_posted_data() ;
// nothing's here... do nothing...
if ( empty ($posted_data))
return ;
//doing other stuff here
return $WPCF7_ContactForm ;
}
}