如果您至少知道如何打开“functions.php”文件,那么如果您只需将其添加到函数的底部,以下内容就可以了。您(子)主题的php文件:
// Hook in
add_filter( \'woocommerce_checkout_fields\' , \'custom_add_checkout_fields\' );
// Our hooked in function - $fields is passed via the filter!
function custom_add_checkout_fields( $fields ) {
$fields[\'billing\'][\'Company\'] = array(
\'label\' => __(\'Company\', \'woocommerce\'),
\'placeholder\' => _x(\'Company Name\', \'placeholder\', \'woocommerce\'),
\'required\' => true,
\'class\' => array(\'form-row-wide\'),
\'clear\' => true
);
$fields[\'billing\'][\'Position\'] = array(
\'label\' => __(\'Position\', \'woocommerce\'),
\'placeholder\' => _x(\'Position\', \'placeholder\', \'woocommerce\'),
\'required\' => true,
\'class\' => array(\'form-row-wide\'),
\'clear\' => true
);
return $fields;
}
这应将字段添加到签出页面,并使其成为必需字段。然后,如果您还想将该信息添加到电子邮件中:
add_filter(\'woocommerce_email_order_meta_keys\', \'my_custom_order_meta_keys\');
function my_custom_order_meta_keys( $keys ) {
$keys[] = \'Company\'; // This will look for a custom field called \'Company\' and add it to emails
$keys[] = \'Position\';
return $keys;
}
从中使用的代码段
this woocommerce docPLEASE NOTE
将其直接添加到函数中。主题的php文件,然后更新主题将其删除-创建子主题是最佳做法。我知道整个答案可能对你没有帮助,但可能对其他人有帮助。