[英]Get custom Fields from registration to Woocommerce Checkout
嗨,我正在使用一个插件来允许雇主注册和发布工作。 在注册中,我创建了自定义字段,它们也在管理员和配置文件中(我需要他们用于计费的增值税 ID)。 我可以自动填充并保存它们,也可以在配置文件或管理后端更新。 但是我必须将它们包含在帐单字段中(可能在公司名称之后并不那么重要),它们会在其中生成到发票中。 我不是程序员,我只知道一点点 html 和 css。 我现在正在尝试 12 个小时,但没有机会到达那里。 我还想让它们无法从用户个人资料中编辑。 这是我保存在子主题functions.php
中的字段,我是在插件作者的帮助下完成的,但由于没有支持,他不会帮助我更多。 插件指南
add_action('iwj_employer_form_after_general',function ($job){
$post_id = $job ? $job->get_id() : '';
?>
<?php
iwj_field_text( '_ico_company', 'IČO spoločnosti*', true, $post_id, null, 'true', '', __( '' ) );
?>
<?php
});
add_action('iwj_admin_employer_form_after_general',function ($post_id){
?>
<?php
iwj_field_text( '_ico_company', 'IČO spoločnosti*', true, $post_id, null, 'true', '', __( '' ) );
?>
<?php
});
add_action('save_post', function($post_id){
if($post_id && get_post_type($post_id) == 'iwj_employer'){
$custom_field_value = sanitize_text_field($_POST['_ico_company']);
update_post_meta($post_id, '_ico_company', $custom_field_value);
}
}, 99);
add_action('iwj_register_process', function($uid){
$user = IWJ_User::get_user($uid);
$post_id = 0;
if($user->is_employer()){
$emp = $user->get_employer();
$post_id = $emp->get_id();
}
if($post_id){
//Add you custom field name process here
update_post_meta($post_id, '_ico_company', sanitize_text_field($_POST['_ico_company']));
}
});
如果有人能帮我解决这个问题,我会非常高兴:)
这将帮助您在结帐中拥有字段。 我添加了一个模拟函数 get_vat_field,因为我还不知道您将如何在结帐中获取增值税字段。
通常,它会在结帐中添加一个附加字段,当结帐完成时,它会将其添加到订单中。 然后显示在订单的订单元中。 您可以在管理面板(订单编辑页面)的订单中找到它。
只需将此添加到您的子主题的functions.php 中即可。
// Our hooked in function – $fields is passed via the filter!
function add_vat_to_checkout_fields( $fields ) {
$fields['billing']['vat'] = array(
'type' => 'text',
'label' => __('VAT', 'woocommerce'),
'placeholder' => _x('VAT', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide hidden'),
'clear' => true,
'value' => get_vat_field('') // this is the function that gets the field from the user account or job post.
);
return $fields;
}
/**
* Display field value on the order edit page
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('VAT').':</strong> ' . get_post_meta( $order->get_id(), 'vat', true ) . '</p>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.