How to modify multiple packages fields – Add more column in Package Section
Copy and paste the following code in your child theme’s functions.php file.
Adding new field in package table
add_filter( 'wpcargo_package_fields', 'wpcargo_package_add_fields_callback' ); function wpcargo_package_add_fields_callback( $package_fields){ //Add fields $package_fields['new_field_1'] = array( 'label' => __('New Field 1', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); $package_fields['new_field_2'] = array( 'label' => __('New Field 2', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); return $package_fields; }
Make fields required.
add_filter( 'wpcargo_package_fields', 'wcp_custom_wpcargo_package_fields', 10, 1 ); function wcp_custom_wpcargo_package_fields( $package_fields ){ /* Change fields to text */ $package_fields['wpc-pm-qty']['required'] = true; $package_fields['wpc-pm-piece-type']['required'] = true; $package_fields['wpc-pm-description']['required'] = true; $package_fields['wpc-pm-length']['required'] = true; $package_fields['wpc-pm-width']['required'] = true; $package_fields['wpc-pm-height']['required'] = true; $package_fields['wpc-pm-weight']['required'] = true; return $package_fields; }
Allow fields accepts decimal value.
add_filter( 'wpcargo_package_fields', 'wcp_custom_wpcargo_package_fields', 10, 1 ); function wcp_custom_wpcargo_package_fields( $package_fields ){ /* Change fields to text */ $package_fields['wpc-pm-qty']['field'] = 'text'; $package_fields['wpc-pm-piece-type']['field'] = 'text'; $package_fields['wpc-pm-description']['field'] = 'text'; $package_fields['wpc-pm-length']['field'] = 'text'; $package_fields['wpc-pm-width']['field'] = 'text'; $package_fields['wpc-pm-height']['field'] = 'text'; $package_fields['wpc-pm-weight']['field'] = 'text'; return $package_fields; }
Removing of fields.
In default these are the availble fields:
- wpc-pm-qty
- wpc-pm-piece-type
- wpc-pm-description
- wpc-pm-length
- wpc-pm-width
- wpc-pm-height
- wpc-pm-weight
- unit-price
- unit-amount
add_filter( 'wpcargo_package_fields', 'modify_package_fields' ); function modify_package_fields( $package_fields){ /* * Removing the Description in package table * Just put the package field name like "wpc-pm-description" * Can remove also the other fields */ unset( $package_fields['wpc-pm-description'] ); return $package_fields; }
Add new column next to Descriptions.
add_filter( 'wpcargo_package_fields', 'modify_package_fields' ); function modify_package_fields( $package_fields){ /* * Removing the Description in package table * Just put the package field name like "wpc-pm-description" * Can remove also the other fields */ unset( $package_fields['wpc-pm-length'] ); unset( $package_fields['wpc-pm-width'] ); unset( $package_fields['wpc-pm-height'] ); unset( $package_fields['wpc-pm-weight'] ); unset( $package_fields['unit-price'] ); unset( $package_fields['unit-amount'] ); unset( $package_fields['wpc-pm-value'] ); return $package_fields; } add_filter( 'wpcargo_package_fields', 'wpcargo_package_add_fields_callback' ); function wpcargo_package_add_fields_callback( $package_fields){ //Add fields $package_fields['hsn_number'] = array( 'label' => __('HSN Number', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); $package_fields['wpc-pm-length'] = array( 'label' => __('Lenght', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); $package_fields['wpc-pm-width'] = array( 'label' => __('Width', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); $package_fields['wpc-pm-height'] = array( 'label' => __('Width', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); $package_fields['wpc-pm-weight'] = array( 'label' => __('Weight', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); $package_fields['unit-price'] = array( 'label' => __('Unit Price', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); $package_fields['unit-amount'] = array( 'label' => __('Amount', 'wpcargo'), 'field' => 'text', 'required' => false, 'options' => array() ); return $package_fields; }