【问题标题】:Woocommerce get custom select fields value at thank you pageWoocommerce 在感谢页面上获取自定义选择字段值
【发布时间】:2013-08-25 23:48:37
【问题描述】:

我正在使用 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" }

【问题讨论】:

    标签: php wordpress checkout woocommerce


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-01-27
      • 2021-04-04
      • 2018-03-12
      • 2015-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多