admin管理员组文章数量:1134597
I'm working on a website that is using woocommerce and yith to add product variations. When the customers wants to buy something, he will have to choose between some product attributes, like the size, etc...
When the customer has finished his purchases, he must fill out a form which will be sent by email to the owner of the site, who will then contact him.
the problem is that, in this said email, there are no product variations (size, etc.). Simply the image, product name and quantity.
We are using the "[yith-request-a-quote-list]" to show in the email, the product list.
The following is my product variations and the email the owner receive.
I'm working on a website that is using woocommerce and yith to add product variations. When the customers wants to buy something, he will have to choose between some product attributes, like the size, etc...
When the customer has finished his purchases, he must fill out a form which will be sent by email to the owner of the site, who will then contact him.
the problem is that, in this said email, there are no product variations (size, etc.). Simply the image, product name and quantity.
We are using the "[yith-request-a-quote-list]" to show in the email, the product list.
The following is my product variations and the email the owner receive.
Share Improve this question asked Sep 25, 2023 at 15:11 sorrowsorrow 31 silver badge3 bronze badges
1 Answer
Reset to default 0You can try this. First, make sure to start a session. Just add this to your theme's functions.php:
function start_session() {
if(!session_id()) {
session_start();
}
}
add_action('init', 'start_session', 1);
Next, hook into WooCommerce to capture the selected attributes:
function capture_selected_attributes($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) {
if($variation_id && is_array($variation)) {
$_SESSION['product_attributes'] = $variation;
}
}
add_action('woocommerce_add_to_cart', 'capture_selected_attributes', 10, 6);
Then, in your contact form, add a hidden field:
[hidden product-attributes default:shortcode-attr]
Now, use a custom shortcode to retrieve the attributes:
function retrieve_product_attributes() {
return isset($_SESSION['product_attributes']) ? implode(", ", $_SESSION['product_attributes']) : '';
}
add_shortcode('shortcode-attr', 'retrieve_product_attributes');
Lastly, in the email template of your contact form, make sure you add the new field:
Product Attributes: [product-attributes]
This way, whenever the form is sent, the product attributes should be included in the email.
本文标签: woocommerce offtopicHow to implement my product variationsattributes in my contact form 7 email
版权声明:本文标题:woocommerce offtopic - How to implement my product variationsattributes in my contact form 7 email? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736791673a1953114.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论