skip to Main Content

I need to send Woocommerce cart items in the email by Contact Form 7 plugin.
I want to make a quick order form on my checkout page only with phone field
but send the cart details in email as well.

2

Answers


  1. Chosen as BEST ANSWER

    Here is a solution:

    Put this code into your functions.php file

    /* Get a cart details as a text */
     function get_cart_content_as_text() {
       $cart_contents = WC()->cart->get_cart();
       $cart_text = '';
       $cart_total = 0;
       foreach ($cart_contents as $cart_item_key => $cart_item) {
           $product = $cart_item['data'];
           $quantity = $cart_item['quantity'];
           $sum = $cart_item['line_total'];
           $cart_total += $sum;
           $product_name = $product->get_name();
           $cart_text .= "Product: $product_name x $quantity Subtotal: $sum n";
       }
       $cart_text .= "---n";
       $cart_text .= "Total: $cart_total";
       return $cart_text;
    }
    
     /* create a new tag for CF7 */
    
     function cf7_add_cart_content_tag() {
       wpcf7_add_form_tag('cart_content', 'cf7_cart_content_handler');
    }
    
    function cf7_cart_content_handler($tag) {
       $cart_content_text = get_cart_content_as_text();
       return '<textarea name="cart_content" readonly>' . esc_textarea($cart_content_text) . 
     '</textarea>';
    }
    
    add_action('wpcf7_init', 'cf7_add_cart_content_tag');
    

    Then use new tag [cart_content] in your form


  2. not working 🙁
    updated same as instructions but not working.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search