How to modify fields in shipment history?

Can I modify fields in shipment history?

Yes you can. Copy and paste the following code in your child theme’s functions.php file.

add_filter( 'wpcargo_history_fields', 'modify_history_fields', 10, 1 );
function modify_history_fields( $history_fields ){
	//Remove fields
	unset( $history_fields['date'] );
	unset( $history_fields['time'] );
	unset( $history_fields['location'] );
	unset( $history_fields['status'] );
	unset( $history_fields['updated-name'] );
	unset( $history_fields['remarks'] );
	
	//Add fields
	$history_fields['new-field'] = array( 
		'label' => __('New Field', 'wpcargo'),
		'field' => 'text',
		'required' => false,
		'options' => array()
	);
	
    //Changing required field by changing value to  false or true 
	$history_fields['location'] = array( 
		'label' => __('Location', 'wpcargo'),
		'field' => 'text',
		'required' => false,
		'options' => array()
	);

	//Update label of field
	$history_fields['updated-name']['label'] = 'New Label';
	return $history_fields;
}

To remove shipment history column from the track result page, copy this code on your child theme’s functions.php:

add_filter( 'wpcargo_history_fields', 'modify_history_fields', 10, 1 );
function modify_history_fields( $history_fields ){
	if(isset( $_REQUEST['wpcargo_tracking_number'] )){
		unset( $history_fields['updated-name'] );
	}
	return $history_fields;
}

To remove the required attributes in all of the shipment history fields, copy this code on your child theme’s functions.php:

add_filter( 'wpcargo_history_fields', 'modify_history_fields', 10, 1 );
function modify_history_fields( $history_fields ){
    //Remove fields
    $history_fields['date']['required'] = false ;
    $history_fields['time']['required'] = false ;
    $history_fields['location']['required'] = false ;
    $history_fields['status']['required'] = false ;
    $history_fields['updated-name']['required'] = false ;
    $history_fields['remarks']['required'] = false ;
     
    return $history_fields;
}

[/php]

To add custom fields in all of the shipment history fields, copy this code on your child theme’s functions.php:

add_filter( 'wpcargo_history_fields', 'custom_additional_history_fields', 10, 1 );
function custom_additional_history_fields( $history_fields ){
    //Add custom field
   $history_fields['custom'] = array(
            'label' => esc_html__('New Field', 'wpcargo'),
            'field' => 'text',
            'required' => 'false',
            'options' => array()
        );
    return $history_fields;
}

Remove “Updated By” column from history fields for guests and wpcargo_client users

add_filter( 'wpcargo_history_fields', 'wpc_remove_updated_name_for_logged_out_users_and_wpcargo_client_roles', 10, 1 );
function wpc_remove_updated_name_for_logged_out_users_and_wpcargo_client_roles( $history_fields ){
    $current_user_roles = wp_get_current_user()->roles;
    if(in_array('wpcargo_client', $current_user_roles) || !is_user_logged_in()) {
        unset($history_fields['updated-name']);
    }
    return $history_fields;
}
0
    0
    Your Cart
    Your cart is emptyReturn to Shop