When importing of shipments I want to remove the old history or multiple packages if shipment is exist

Note: please copy and paste this code in functions.php of your current theme.

		function custom_wpcie_import_package_shipment_data_callback( $import_data, $explode_value, $shipment_id, $key ){
		if( $key == 'wpcargo_shipments_update' || $key == 'wpc-multiple-package' ){
			if( $key == 'wpcargo_shipments_update' ){
				$fields = wpcargo_history_fields();
			}else{
				$fields = wpcargo_package_fields();
			}		
			$import_data = array();
			foreach( $explode_value as $value ){
				$get_explode_value = array_map( 'trim', explode( " * ", $value ) );
	            $_history_val = array();
	            foreach( $fields as $history_meta => $history_value ){
	                foreach( $get_explode_value as $_explode_value ){
	                    if( strpos( $_explode_value, $history_value['label'].'=' ) !== false  ){
	                        $str_value = str_replace( $history_value['label'].'=', '', $_explode_value );
	                        $_history_val[$history_meta]	= sanitize_text_field( $str_value );
	                    }
	                }
	                if( !array_key_exists($history_meta, $_history_val ) ){
	                    $_history_val[$history_meta] = '';
	                }
	            }
	            $import_data[] = $_history_val;
			}
		}
		return $import_data;
	}
	add_filter( 'wpcie_import_package_shipment_data', 'custom_wpcie_import_package_shipment_data_callback', 10, 4 );
	
0
    0
    Your Cart
    Your cart is emptyReturn to Shop