• Resolved mwrweb

    (@mwrweb)


    Hi, I’m trying to get input value from custom field. And I already tried this code in my function.php but not working.

    //GET CUSTOM FIELD VALUE - BILLING FIRST NAME
    function fieldvalue_shortcode() {
        $getfieldvalue = get_post_meta($order_id, 'billing_first_name', true);
    	return $getfieldvalue;
    }
    add_shortcode('get_customfield_value', 'fieldvalue_shortcode');

    I’m not good at coding~ Can anyone help?

Viewing 1 replies (of 1 total)
  • Plugin Author ThemeHigh

    (@themehigh)

    The code that you have given is correct and you will get custom field value using it.

    The only issue is that you need to get the order id in the code. Getting an order ID depends on which page/action you use this shortcode. You have to find out how you will get the order ID on the page that you use shortcode.

    The above code is to get the “billing_first_name” field value. So you need to modify the code as per your field name.

    //GET CUSTOM FIELD VALUE - billing_your_custom_field
    function fieldvalue_shortcode() {
    
    	// Get order ID in order detail page
    	$order_id = get_the_ID();
    
        $getfieldvalue = get_post_meta($order_id, 'billing_your_custom_field', true);
    	return $getfieldvalue;
    }
    add_shortcode('get_customfield_value', 'fieldvalue_shortcode');

    We hope this helps.

    Thank you!

Viewing 1 replies (of 1 total)

The topic ‘Get input value from custom field’ is closed to new replies.