0

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.

enter image description here enter image description here

1 Answer 1

0

You 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.