ARTICLE AD BOX
There are two options for placing an order in the cart on the website:
Standard WooCommerce order placement. Ordering through a manager using the Contact Form 7 order form.I use code that adds items from the cart to the end of a specific Contact Form 7 form.
add_filter( 'wpcf7_before_send_mail', 'wpcf7_before_send_mail_start_function' ); function wpcf7_before_send_mail_start_function($cf7){ $mail=$cf7->prop('mail'); if($mail){ $contact_form = $cf7->get_current(); $contact_form_id = $contact_form -> id; if ($contact_form_id == 2384){ if ( !is_admin()){ $product_name = ""; wc()->frontend_includes(); WC()->session = new WC_Session_Handler(); WC()->session->init(); WC()->customer = new WC_Customer( get_current_user_id(), true ); WC()->cart = new WC_Cart(); foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) { $product_name = $product_name.apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key )."\n"; } } $my = $product_name; }else{ $my = ""; } $mail['body'].="\n\r".$my; // Add the contents of the cart to the end of the email body. WC()->cart->empty_cart(); WC()->session->set('cart', array()); } $cf7->set_properties(array('mail'=>$mail)); } }Unfortunately, the products from the cart are not displayed in the email. No errors are shown.
How can I fix the code and make it more correct?
