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.