I am selling a course product using woocommerce. The course uses wc fields factory for custom product fields for student name and student email address. The field name for student email address is "student_email". I am then trying to take the value from that field (the email address) and use that as the recipient for an email from woocommerce upon the purchase of this product.
The values inputted do show up on the cart page, the order receipt emails, etc. The custom email template I set up does work (it currently sends to the admin email until I get this to work). But I can't figure out how to grab the student email address value to use as the recipient.
I've tried several things, including the following:
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
// Get "student email" custom field value
$student_emails = get_post_meta($order_id, "wccpf_student_email", true );
$this->recipient = $student_emails;
and
function custom_add_to_cart_action_handler($_cart_item_data, $_product_id) {
if(isset($_cart_item_data[“wccpf_student_email”])) {
$value = $_cart_item_data[“wccpf_student_email”];
return $value;
}
}
add_filter(‘woocommerce_add_cart_item_data’, array( $this, ‘custom_add_to_cart_action_handler’ ), 100, 2);
$this->recipient = $value;
This is done within my custom email class php file. But nothing seems to grab the values of the student_email custom product field. Any help would be much appreciated!