How to fetch product name to contact form mail body
-
Hello
I would like to display the product name in the email body in the following format: Product Title: [productname]
I was using the following code, which worked fine with an older version of Contact Form 7. However, after updating the plugin to a higher version, this code started causing a ‘500 Internal Server Error’ at wp-json/contact-form-7/v1/contact-forms/550/feedback.
function add_product_names_to_contact_form( $posted_data ) {
$product_names = array();
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( ‘woocommerce_cart_item_product’, $cart_item[‘data’], $cart_item, $cart_item_key );
$product_names[] = $_product->get_name();
}// Set the product names in the contact form data
$posted_data[‘productname’] = implode( ‘, ‘, $product_names );
return $posted_data;
}
add_filter( ‘wpcf7_posted_data’, ‘add_product_names_to_contact_form’ );In this situation, how can I retrieve the product name and include it in the email body?”
- The topic ‘How to fetch product name to contact form mail body’ is closed to new replies.