/**
  * Generate Shipping mode configuration back-office interface
  * @param string $key
  * @param array $shipping_mode
  * @return string
  */
 function generate_shipping_mode_interface($k, $shipping_mode)
 {
     global $wpdb;
     $tpl_component = array();
     $shipping_mode_option = get_option('wps_shipping_mode');
     $default_shipping_mode = !empty($shipping_mode_option['default_choice']) ? $shipping_mode_option['default_choice'] : '';
     $countries = unserialize(WPSHOP_COUNTRY_LIST);
     /** Default Weight Unity **/
     $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity');
     $query = $wpdb->prepare('SELECT name FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
     $unity = $wpdb->get_var($query);
     $fees_data = !empty($shipping_mode) & !empty($shipping_mode['custom_shipping_rules']) && !empty($shipping_mode['custom_shipping_rules']['fees']) ? $shipping_mode['custom_shipping_rules']['fees'] : array();
     if (is_array($fees_data)) {
         $wps_shipping = new wps_shipping();
         $fees_data = $wps_shipping->shipping_fees_array_2_string($fees_data);
     }
     ob_start();
     require wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-interface");
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }
 /**
  * AJAX - Delete Custom shipping Rule
  */
 function wpshop_ajax_delete_shipping_rule()
 {
     global $wpdb;
     $wps_shipping = new wps_shipping();
     $fees_data = !empty($_POST['fees_data']) ? $_POST['fees_data'] : null;
     $country_and_weight = !empty($_POST['country_and_weight']) ? $_POST['country_and_weight'] : null;
     $datas = explode("|", $country_and_weight);
     $country = $datas[0];
     $weight = $datas[1];
     $shipping_mode_id = $datas[2];
     $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data));
     /** Check the default weight unity **/
     // 		$weight_unity_id = get_option('wpshop_shop_default_weight_unity');
     // 		if ( !empty($weight_unity_id) ) {
     // 			$query = $wpdb->prepare('SELECT unit FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id=%d', $weight_unity_id);
     // 			$weight_unity = $wpdb->get_var( $query );
     // 			if( $weight_unity == 'kg' ) {
     // 				$weight = $weight * 1000;
     // 			}
     // 		}
     if (array_key_exists($country, $shipping_rules)) {
         if (array_key_exists((string) $weight, $shipping_rules[$country]['fees'])) {
             unset($shipping_rules[$country]['fees'][$weight]);
         }
         if (empty($shipping_rules[$country]['fees'])) {
             unset($shipping_rules[$country]);
         }
     }
     foreach ($shipping_rules as $k => $shipping_rule) {
         if (!isset($shipping_rule['fees'])) {
             unset($shipping_rules[$k]);
         }
     }
     $status = true;
     if (!empty($shipping_rules)) {
         $rules = $wps_shipping->shipping_fees_array_2_string($shipping_rules);
     } else {
         $rules = '';
     }
     $reponse = array('status' => $status, 'reponse' => $rules);
     echo json_encode($reponse);
     die;
 }