Woocommerce - 购物车页面上的验证

时间:2021-02-09 08:17:15

标签: wordpress validation woocommerce shopping-cart woocommerce-theming

我为特定的运输方式提交了自定义文件(请参见屏幕截图)。

在进行结帐之前是否有钩子/操作来验证此字段。当我将该字段设置为 df.rename(columns={('2019', 'S1', 'OVERALL', 'SUBJECT PERCENTILE'):('2019', 'S1', 'OVERALL', 'ENG SUBJECT PERCENTILE')}, inplace=True) 时,验证将在结帐页面触发,但我希望在购物车 页面进行验证。

enter image description here

验证:

required

** 更新: **

就像@LoicTheAztec 在这里提到的完整代码一样。

一切正常。来自购物车的自定义输入值将在结账时显示并在订单确认后保存在数据库中。但是当自定义输入为空时,我不知道我必须将验证放在购物车页面的哪个位置,因为购物车上的所有内容都在 ajax 上。

//Validate the custom selection field
add_action('woocommerce_checkout_process', 'carrier_company_checkout_validation');
function carrier_company_checkout_validation() {
    Load settings and convert them in variables
    extract( custom_field_settings() );

    if(  isset( $_POST[$field_id] ) && empty( $_POST[$field_id] ) )
        wc_add_notice(
            sprintf( __("Please select a %s as it is a required field.","woocommerce"),
            '<strong>' . $label_name . '</strong>'
        ), "error" );
}

1 个答案:

答案 0 :(得分:0)

我认为您正在寻找的钩子是 NavigationView { Form { Section { TextField("title", text: $title) Picker(selection: $category, label: Text("category")) { ForEach(0..<categories.count) { index in Text(categories[index]).tag(index) } } } } } ,它是在继续结帐之前验证购物车项目的钩子。

我不能 100% 确定您是否可以使用 woocommerce_check_cart_items 以相同的方式获得该字段,但值得一试。