Hi I have the latest wordpress and woocommerce versions as of today,
My question is how can I add a text area to the cart page for the client to full in if they are looking for a product that we do not have on our website. this should also show on view order. and on the emails to the client and to admin of the website.
I have the following code that shows on the cart page but it does not carry over to the view order and emails at all
what I have tried is the following
// Add custom fields to the cart item data
function custom_add_to_cart_item_data($cart_item_data, $product_id, $variation_id)
{
if (isset($_POST['request_product']) && $_POST['request_product'] === 'yes') {
$cart_item_data['custom_request'] = array(
'product_name' => sanitize_text_field($_POST['custom_product_name']),
'quantity' => intval($_POST['custom_quantity']),
);
}
return $cart_item_data;
}
add_filter('woocommerce_add_cart_item_data', 'custom_add_to_cart_item_data', 10, 3);
// Display custom fields in the cart
function custom_render_cart_item($title, $cart_item, $cart_item_key)
{
if (isset($cart_item['custom_request'])) {
$title .= '<br><strong>Custom Request:</strong>';
$title .= '<br>Product: ' . esc_html($cart_item['custom_request']['product_name']);
$title .= '<br>Quantity: ' . esc_html($cart_item['custom_request']['quantity']);
}
return $title;
}
add_filter('woocommerce_cart_item_name', 'custom_render_cart_item', 10, 3);