Anonymous
Как отображать элементы корзины woocommerce в форме и почте с помощью контактной формы 7?
Сообщение
Anonymous » 24 июн 2024, 20:59
У меня есть этот код для создания пользовательского тега для отображения элементов корзины woocommerce в форме cf7 и отправки элементов корзины в уведомлениях по электронной почте. Но в электронной почте я не могу понять, как отображать элементы корзины так, как они отображаются в форме: с изображением продукта, названием продукта, ценой и т. д.
В электронной почте я смог показать список продуктов только в скучном и ненужном виде. приемлемым способом.
Кроме того, я также создаю собственный тег для отображения общей суммы корзины без учета налога и суммы доставки (потому что это запрос ценового предложения).
Это мой рабочий код.
Код: Выделить всё
// add "cart" tag in Contact Form 7
add_action('wpcf7_init', 'cartTag');
function cartTag() {
wpcf7_add_form_tag('cart', 'cartItems', true);
}
// loop for cart items in "cart" tag Contact Form 7
function cartItems($tag) {
if (is_null(WC()->cart)) {
wc_load_cart();
}
$name = $tag['name'];
if (empty($name)) {
return '';
}
$items = WC()->cart->get_cart();
$output = '';
$inputValue = "";
$cart = [
'total' => WC()->cart->total,
'products' => []
];
foreach ($items as $item => $values) {
$_product = wc_get_product($values['data']->get_id());
$item_image = $values['data']->get_image(array(0, 30));
$price = wc_get_price_excluding_tax($_product);
$price = $values['line_total'];
$price = number_format($price, 2, ",", ".");
$output .= '' . $item_image;
$output .= '
' . $_product->get_title() . '
';
$output .= '
Quantity: ';
$output .= $values['quantity'] . '
';
$output .= '
Price: € ' . $price . ' exc. tax
';
// for email (CF7)
$inputValue .= 'Product: ' . $_product->get_title() . ' • Quantity: ' . $values['quantity'] . ' • Price: € ' . $price . ' exc. tax
';
$cart['products'][] = [
'name' => $_product->get_title(),
'qty' => $values['quantity'],
'price' => $price,
'link' => $_product->get_permalink()
];
}
// set total cart without shipping amount - by Krikdesign
$total = WC()->cart->subtotal_ex_tax;
$shipping = WC()->cart->shipping_total;
$total = number_format($total, 2, ",", ".");
$output .= '
Products total:[/b] € ' . $total . ' exc. tax
';
$output .= '';
$output .= '';
$output .= '';
$output .= '';
return $output;
}
// add "total" tag in Contact Form 7
add_action('wpcf7_init', 'totalTag');
function totalTag() {
wpcf7_add_form_tag('total', 'totalItem', true);
}
// Total exc. tax in "total" tag Contact Form 7
function totalItem($tag) {
if (is_null(WC()->cart)) {
wc_load_cart();
}
$name = $tag['name'];
if (empty($name)) {
return '';
}
$output = '';
$total = WC()->cart->subtotal_ex_tax;
$total = number_format($total, 2, ",", ".");
$inputValue = '€ ' . $total . ' exc. tax';
$output .= '';
$output .= '';
return $output;
}
список товаров в корзине в моей форме
список товаров в корзине в моем электронном письме
Спасибо за любую помощь
Подробнее здесь:
https://stackoverflow.com/questions/786 ... act-form-7
1719251957
Anonymous
У меня есть этот код для создания пользовательского тега для отображения элементов корзины woocommerce в форме cf7 и отправки элементов корзины в уведомлениях по электронной почте. Но в электронной почте я не могу понять, как отображать элементы корзины так, как они отображаются в форме: с изображением продукта, названием продукта, ценой и т. д.[b]В электронной почте я смог показать список продуктов только в скучном и ненужном виде. приемлемым способом. Кроме того, я также создаю собственный тег для отображения общей суммы корзины без учета налога и суммы доставки (потому что это запрос ценового предложения). Это мой рабочий код. [code]// add "cart" tag in Contact Form 7 add_action('wpcf7_init', 'cartTag'); function cartTag() { wpcf7_add_form_tag('cart', 'cartItems', true); } // loop for cart items in "cart" tag Contact Form 7 function cartItems($tag) { if (is_null(WC()->cart)) { wc_load_cart(); } $name = $tag['name']; if (empty($name)) { return ''; } $items = WC()->cart->get_cart(); $output = ''; $inputValue = ""; $cart = [ 'total' => WC()->cart->total, 'products' => [] ]; foreach ($items as $item => $values) { $_product = wc_get_product($values['data']->get_id()); $item_image = $values['data']->get_image(array(0, 30)); $price = wc_get_price_excluding_tax($_product); $price = $values['line_total']; $price = number_format($price, 2, ",", "."); $output .= '' . $item_image; $output .= ' ' . $_product->get_title() . ' '; $output .= ' Quantity: '; $output .= $values['quantity'] . ' '; $output .= ' Price: € ' . $price . ' exc. tax '; // for email (CF7) $inputValue .= 'Product: ' . $_product->get_title() . ' • Quantity: ' . $values['quantity'] . ' • Price: € ' . $price . ' exc. tax '; $cart['products'][] = [ 'name' => $_product->get_title(), 'qty' => $values['quantity'], 'price' => $price, 'link' => $_product->get_permalink() ]; } // set total cart without shipping amount - by Krikdesign $total = WC()->cart->subtotal_ex_tax; $shipping = WC()->cart->shipping_total; $total = number_format($total, 2, ",", "."); $output .= ' Products total:[/b] € ' . $total . ' exc. tax '; $output .= ''; $output .= ''; $output .= ''; $output .= ''; return $output; } // add "total" tag in Contact Form 7 add_action('wpcf7_init', 'totalTag'); function totalTag() { wpcf7_add_form_tag('total', 'totalItem', true); } // Total exc. tax in "total" tag Contact Form 7 function totalItem($tag) { if (is_null(WC()->cart)) { wc_load_cart(); } $name = $tag['name']; if (empty($name)) { return ''; } $output = ''; $total = WC()->cart->subtotal_ex_tax; $total = number_format($total, 2, ",", "."); $inputValue = '€ ' . $total . ' exc. tax'; $output .= ''; $output .= ''; return $output; } [/code] список товаров в корзине в моей форме список товаров в корзине в моем электронном письме Спасибо за любую помощь Подробнее здесь: [url]https://stackoverflow.com/questions/78633472/how-to-display-woocommerce-cart-items-in-form-and-mail-using-contact-form-7[/url]