小编Kyl*_*yle的帖子

woocommerce 结帐页面上的自定义字段

我试图在 woocommerce 结帐顶部放置两个自定义字段(理想情况下是购物车页面,但我在网上找不到任何有关此操作的信息)

我已经在结帐页面上显示了两个自定义字段,但由于 php 知识非常有限,我尝试创建一个下拉菜单等。从表面上看,一切似乎都很好。这些字段显示在结账页面上,但每当我输入信息并尝试继续执行订单以测试这些值是否显示在感谢页面和电子邮件上时,系统都会要求我在这些必填字段中填写信息。由于某种原因,页面无法识别字段为空

我用了这篇文章...https://www.businessbloomer.com/woocommerce-add-custom-checkout-field-php/

但我必须对其进行大量编辑才能达到这一点。我确信有很多错误。

add_action('woocommerce_before_checkout_form', 'custom_add_custom_checkout_fields');

function custom_add_custom_checkout_fields($checkout)
{
    echo '<h3>Event Information</h3>';

    // Get the current user ID
    $user_id = get_current_user_id();

    // Fetch user meta data
    $saved_event_venue = $current_user->event_venue;
    $saved_hall_stand_number = $current_user->hall_stand_number;

    woocommerce_form_field('event_venue', array(
        'type' => 'select',
        'class' => array('form-row-wide'),
        'label' => 'Event/Expo & Venue',
        'options' => array(
            '' => 'Select an option',
            'event1' => 'Event 1 Venue',
            'event2' => 'Event 2 Venue',
            'event3' => 'Event 3 Venue'
            // Add more options as needed
        ),
        'required' …
Run Code Online (Sandbox Code Playgroud)

php wordpress checkout custom-fields woocommerce

5
推荐指数
1
解决办法
87
查看次数

标签 统计

checkout ×1

custom-fields ×1

php ×1

woocommerce ×1

wordpress ×1