首页 文章

Woocommerce在感谢页面获取自定义选择字段值

提问于
浏览
2

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

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字段值 . 但它没有用 .

$checkout->get_points_go_to();

我有这些值以及如何导出边值 .

["_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" }

1 回答

  • 3

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

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

相关问题