• Resolved maipiusenza

    (@maipiusenza)


    Hi, is it possible to get the label text?

    With

    get_post_meta($order->id, ‘_field_name’, true)

    I get the field value, I need the label.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Tomasz WP Desk

    (@tomaszwp)

    Hello @maipiusenza

    Values are retrieved with the code but the labels should be hard-coded.

    Below I am pasting an example of the code we use for our invoice plugin so that it shows the VAT Number field on the invoice. The label is fixed there (see the 6th line of code).

    <?php
    $order = wc_get_order( $invoice->get_order_id() );
    if (!empty($order->get_meta('_billing_vat_number'))) {
    ?>
    <tr><td><?php
    echo \__('VAT Number', 'flexible-invoices-woocommerce');
    ?>: <?php
    echo $order->get_meta('_billing_vat_number');
    ?></td></tr>
    <?php
    }
    ?>
    </table>
    <?php
    Thread Starter maipiusenza

    (@maipiusenza)

    Thanks, but it is a select, with your code I get the label of the field, not of the option:
    https://snipboard.io/CZ5hcN.jpg

    I need the code for the label indicated by the red arrow

    Plugin Support Tomasz WP Desk

    (@tomaszwp)

    Hello @maipiusenza

    The value can be the same as the label. Getting the value will be the same as getting the label in this case.
    We do not have code to insert field option labels instead of field labels.

    Thread Starter maipiusenza

    (@maipiusenza)

    To those who need it (not thanks to plugin support!):

    The label is stored only in the plugin settings, not in post meta.
    Moreover, be careful because value and label are in a single string separated by ” : “, so if you use it in your “value”, you will break it (there is no check to replace the character).

    // get the array of the plugin settings
    $settingList = get_option( 'inspire_checkout_fields_settings' );
    // get value : option of the desired field (in this case "my_field_name" under "order" block)
    $myString_value_label = $settingList ['order']['my_field_name']['option'];
    // get only the label
    $myString_label = substr($myString_value_label ,strpos($myString_value_label ,' : ')+3);

    Hope could be helpful.
    Nadia

    • This reply was modified 2 years, 10 months ago by maipiusenza.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hot to get the label text?’ is closed to new replies.