如何以 CF7 表单电子邮件发送 woocommerce 购物车项目

问题描述 投票:0回答:2

我需要通过 Contact Form 7 插件在电子邮件中发送 Woocommerce 购物车项目。 我想在结帐页面上制作一个仅包含电话字段的快速订单表 但也要通过电子邮件发送购物车详细信息。

wordpress email woocommerce cart contact-form-7
2个回答
2
投票

解决方案如下:

将此代码放入您的 functions.php 文件中

/* 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');

然后在表单中使用新标签[cart_content]


0
投票

在此函数中如何将文本区域更改为输入字段

© www.soinside.com 2019 - 2024. All rights reserved.