如何将自定义单选框添加到WooCommerce帐单页面并通过此字段更改总价?

时间:2017-09-22 作者:Юксел Османов

假设我需要将表单顶部的自定义无线电字段(公司或个人)添加到的帐单中。如果访客检查人员,他们应缴纳21%的税,并且他们选择位于NL的公司,他们也应缴纳21%的税。其他情况下他们应该免税吗?有什么想法吗?

这就是我所尝试的:

add_filter(\'woocommerce_billing_fields\', \'custom_woocommerce_billing_fields\');
函数custom\\u woocommerce\\u billing\\u字段($字段){

$fields[\'customer_type\'] = array(
    \'label\' => __(\'Bedrijf\', \'woocommerce\'),
    \'placeholder\' => _x(\'Bedrijf\', \'placeholder\', \'woocommerce\'),
    \'required\' => false,
    \'clear\' => false,
    \'type\' => \'checkbox\',
    \'class\' => array(\'my-css\'),
);

$fields[\'customer_type_personal\'] = array(
    \'label\' => __(\'Persoonlijke\', \'woocommerce\'),
    \'placeholder\' => _x(\'Persoonlijke\', \'placeholder\', \'woocommerce\'),
    \'required\' => false,
    \'clear\' => false,
    \'type\' => \'checkbox\',
    \'class\' => array(\'my-css-2\'),
);

return $fields;
}

1 个回复
SO网友:edgematrix

Try it

add_filter(\'woocommerce_billing_fields\', \'custom_woocommerce_billing_fields\');

function custom_woocommerce_billing_fields($fields)
{

    $fields[\'billing_options\'] = array(
        \'label\' => __(\'Ordering Method\', \'woocommerce\'), // Add custom field label
        \'placeholder\' => _x(\'Your NIF here....\', \'placeholder\', \'woocommerce\'), // Add custom field placeholder
        \'required\' => true, // if field is required or not
        \'clear\' => false, // add clear or not
        \'type\' => \'radio\', // add field type
        \'class\' => array(\'form-group\'),    // add class name
        \'options\'         => array(
        \'privato_cittadino\'         => \'Privato cittadino\',
        \'azienda_professionista\'    => \'Azienda o libero professionista\',
      ),

    );
结束