コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Generate cutom fees resume table
  * @param array $fees_data
  * @param string $key
  */
 function generate_shipping_rules_table($fees_data, $shipping_mode_id)
 {
     global $wpdb;
     $result = '';
     if (!empty($fees_data)) {
         $wps_shipping = new wps_shipping();
         $shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data));
         $result = '';
         $tpl_component = '';
         $tpl_component['CUSTOM_SHIPPING_RULES_LINES'] = '';
         $tpl_component['SHIPPING_MODE_ID'] = $shipping_mode_id;
         $country_list = unserialize(WPSHOP_COUNTRY_LIST);
         $weight_defaut_unity_option = get_option('wpshop_shop_default_weight_unity');
         $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id=%d', $weight_defaut_unity_option);
         $unity = $wpdb->get_var($query);
         ob_start();
         require wpshop_tools::get_template_part(WPS_SHIPPING_MODE_DIR, $this->template_dir, "backend", "shipping-mode-configuration-custom-rules-table");
         $result = ob_get_contents();
         ob_end_clean();
     }
     return $result;
 }
<?php

$wps_shipping = new wps_shipping();
$shipping_rules = $wps_shipping->shipping_fees_string_2_array(stripslashes($fees_data));
if (!empty($shipping_rules)) {
    ?>

	<div class="wps-table-header wps-table-row">
		<div class="wps-table-cell"><?php 
    _e('Country', 'wpshop');
    ?>
</div>
		<div class="wps-table-cell"><?php 
    _e('Weight', 'wpshop');
    ?>
</div>
		<div class="wps-table-cell"><?php 
    _e('Price', 'wpshop');
    ?>
</div>
		<div class="wps-table-cell"><?php 
    _e('Delete', 'wpshop');
    ?>
</div>
	</div>

	<?php 
    foreach ($shipping_rules as $shipping_rule) {
        $country_name = '';
        $code_country = explode('-', $shipping_rule['destination']);
        $code_country = $code_country[0];