Woocommerce在“谢谢”页面上获得自定义选择字段值 [英] Woocommerce get custom select fields value at thank you page

查看:94
本文介绍了Woocommerce在“谢谢”页面上获得自定义选择字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用woocommerce插件,我想在结帐页面上添加自定义选择字段。我在function.php页面上添加了一个函数并挂钩。它显示在结帐页面上。但是我如何才能在thankyou.php页面中获取该字段的值。

I am using woocommerce plugin and i want to add custom select field at the checkout page. I added a function and hook to function.php page. It's displaying at the checkout page. But how can i get the value of that field in the thankyou.php page.

add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');

function my_custom_checkout_field($checkout) {
    echo '<div id="my_custom_checkout_field"><h3>'
        . __('Select Where Your Points Go') . '</h3>';

    woocommerce_form_field(
        'points_go_to', array(
            'type'     => 'select',
            'class'    => array('form-row-wide'),
            'required' => true,
            'label'    => __('Select a Side'),
            'options'  => array(
                'dfault' => __('Default1', 'woocommerce'),
                'left'   => __('Left Side', 'woocommerce'),
                'right'  => __('Right Side', 'woocommerce')
            )
        ),
        $checkout->get_value('points_go_to')
    );

    echo '</div>';
}

我试图以此方式获取points_to_go字段值。

I tried to get the points_to_go field value in this way. But it did not work.

$checkout->get_points_go_to();

我有这些值以及如何得出边值。

I have these values and how to derive side value.

["_side"]=> array(1) { [0]=> string(6) "dfault" } ["_shipping_country"]=> array(1) {   
[0]=> string(2) "LK" } ["_shipping_first_name"]=> array(1) { [0]=> string(7) "saman"
} ["_shipping_last_name"]=> array(1) { [0]=> string(11) "perera" }


推荐答案

您可以尝试使用以下代码。

You can try using the following code.

$side=$order->order_custom_fields['_side'][0];

这篇关于Woocommerce在“谢谢”页面上获得自定义选择字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆