• Resolved corayl

    (@corayl)


    hello, the first thing is to congratulate you, the plugin is great.
    I have a selection field in the checkout page with the name of my vendors, in which the customer must select it so that his vendor can take care of his order. I need to put the name of the chosen vendor in the email subject, I have tried {vendor_field} but it doesn’t work. Could you help me, I thank you very much.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author ThemeHigh

    (@themehigh)

    Can you please try the below code in your theme’s functions.php file?

    add_filter( 'woocommerce_email_format_string' , 'add_custom_email_format_string', 10, 2 );
    function add_custom_email_format_string( $string, $email ) {
        $order = $email->object;
        $value = $order->get_meta('field_name') ? $order->get_meta('field_name') : '';
        $string = $string.' '.$value;
        return $string;
    }

    Replace field_name with your field name.

    We hope this helps.

    Thank you!

    Thread Starter corayl

    (@corayl)

    Yes it works, but I am getting the “option value” and need the “option text” to appear.
    What do i need to change?
    Thanks

    Plugin Author ThemeHigh

    (@themehigh)

    Can you please try the below code?

    add_filter( 'woocommerce_email_format_string' , 'add_custom_email_format_string', 10, 2 );
    function add_custom_email_format_string( $string, $email ) {
        $order = $email->object;
        $field_value = $order->get_meta('field_name') ? $order->get_meta('field_name') : '';
        $checkout = new WC_Checkout();
        $checkout_fields = $checkout->get_checkout_fields();
        $return_value = '';
        if(!empty($checkout_fields)) {
            foreach($checkout_fields as $values) {
                foreach ($values as $value) {
                    if(isset($value['name']) &&  $value['name'] == 'field_name'){
                        $options = $value['options'];
                        foreach ($options as $key => $option) {
                            if($key == $field_value){
                                $return_value = $option;
                            }
                        }
                    }
                }
            }
        }
        $string = $string.' '.$return_value;
        return $string;
    }

    We hope this helps.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Insert name of a field in the subject of the order email’ is closed to new replies.