0
votes

Hi i am using a plugin to allow employers to register and post jobs. In the registration I have created custom fields they are also in the admin and in the Profile (VAT IDs they I need for billing). I can automaticaly fill and save them also update in the Profile or admin back-end. But I have to include them in the billing fields (not so important where maybe after company name) where they are generated into the invoice. I am not a programmer I only know html and css little bit. I am trying now for 12 hours and no chance to get it there. I would also like to make them not-editable from user profile. This are my fields saved in the child-theme functions.php I have done this with the help from Plugin author but he will not help me more because of no support. Plugin guide

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']));

    }
});

I would be mega happy if someone could help me out with this :)

1
I have two questions: 1. In the checkout, is the user logged in? If yes, what function do you use to get the user id from the session. If the user isn't logged in, how do you expect to access the vat from the post? 2. The VAT needs to be saved in order to processed into an invoice? How do you do expect to do that?Hendrik Vlaanderen
Hi. User has to be logged in because there is no way to add products. The invoice is generated by a plugin taking all checkout fields. but I don't know if this would work.Martin Kurka

1 Answers

1
votes

This will help you to have the fields in the checkout. I added a mock function get_vat_field, because I don't know yet how you are going to get the VAT field in the checkout.

Generally, it adds an additional field to the checkout, and when the checkout is completed, it adds it to the order. Which then is displayed in the order meta of the order. You can find that in the order itself in the admin panel (order edit page).

Simply add this to your functions.php of your child theme.

// 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>';
}