@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if ( !defined( 'ABSPATH' ) ) exit; |
|
| 1 | +<?php if (!defined('ABSPATH')) exit;
|
|
| 2 | 2 | class wps_shipping {
|
| 3 | 3 | function __construct() {
|
| 4 | 4 | |
@@ -11,41 +11,41 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | function shipping_fees_string_2_array($fees_string) {
|
| 13 | 13 | $data = array(); |
| 14 | - if(!empty($fees_string) && !is_array($fees_string) ) {
|
|
| 15 | - if(preg_match_all('#{[^{]+}#', $fees_string, $cont)){
|
|
| 16 | - foreach($cont[0] as $c) {
|
|
| 14 | + if (!empty($fees_string) && !is_array($fees_string)) {
|
|
| 15 | + if (preg_match_all('#{[^{]+}#', $fees_string, $cont)) {
|
|
| 16 | + foreach ($cont[0] as $c) {
|
|
| 17 | 17 | preg_match_all('#([a-z]+) ?: ?"(.+)"#', $c, $atts);
|
| 18 | 18 | $temp_data = array(); |
| 19 | 19 | $country_code = ''; |
| 20 | - foreach($atts[1] as $key => $value) {
|
|
| 21 | - $temp_data[$value] = $atts[2][$key]; |
|
| 22 | - if($value=='destination') {
|
|
| 20 | + foreach ($atts[1] as $key => $value) {
|
|
| 21 | + $temp_data[$value] = $atts[2][$key]; |
|
| 22 | + if ($value == 'destination') {
|
|
| 23 | 23 | $country_code = $atts[2][$key]; |
| 24 | 24 | } |
| 25 | - elseif($value=='fees') {
|
|
| 25 | + elseif ($value == 'fees') {
|
|
| 26 | 26 | $fees_data = array(); |
| 27 | 27 | $fees = explode(',', $atts[2][$key]);
|
| 28 | - foreach($fees as $fee){
|
|
| 28 | + foreach ($fees as $fee) {
|
|
| 29 | 29 | $fee_element = explode(':', $fee);
|
| 30 | - $fees_data[trim($fee_element[0])] = trim($fee_element[1]); |
|
| 30 | + $fees_data[trim($fee_element[0])] = trim($fee_element[1]); |
|
| 31 | 31 | } |
| 32 | 32 | $number = count($fees_data); |
| 33 | 33 | |
| 34 | 34 | $fees_data_1 = array(); |
| 35 | 35 | preg_match_all('#([0-9]+\.?[0-9]?+) ?: ?([0-9]+\.?[0-9]?+)#', $atts[2][$key], $fees);
|
| 36 | - foreach($fees[1] as $_key => $_value) {
|
|
| 37 | - $fees_data_1[$_value] = $fees[2][$_key]; |
|
| 36 | + foreach ($fees[1] as $_key => $_value) {
|
|
| 37 | + $fees_data_1[$_value] = $fees[2][$_key]; |
|
| 38 | 38 | } |
| 39 | 39 | $number_1 = count($fees_data_1); |
| 40 | 40 | if ($number == $number_1) {
|
| 41 | - $temp_data[$value] = $fees_data; |
|
| 41 | + $temp_data[$value] = $fees_data; |
|
| 42 | 42 | } |
| 43 | 43 | else {
|
| 44 | - $temp_data[$value] = $fees_data_1; |
|
| 44 | + $temp_data[$value] = $fees_data_1; |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | - if(!empty($country_code)) {
|
|
| 48 | + if (!empty($country_code)) {
|
|
| 49 | 49 | $data[$country_code] = $temp_data; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -62,21 +62,21 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | function shipping_fees_array_2_string($fees_array) {
|
| 64 | 64 | $string = ''; |
| 65 | - if(!empty($fees_array)) {
|
|
| 66 | - foreach($fees_array as $d) {
|
|
| 67 | - $string .= '{'."\n";
|
|
| 68 | - foreach($d as $att => $value) {
|
|
| 65 | + if (!empty($fees_array)) {
|
|
| 66 | + foreach ($fees_array as $d) {
|
|
| 67 | + $string .= '{' . "\n";
|
|
| 68 | + foreach ($d as $att => $value) {
|
|
| 69 | 69 | $val = ''; |
| 70 | - if($att=='fees') {
|
|
| 71 | - foreach($value as $_k=>$_value) $val .= $_k.':'.$_value.', '; |
|
| 72 | - $val = substr($val,0,-2); |
|
| 70 | + if ($att == 'fees') {
|
|
| 71 | + foreach ($value as $_k=>$_value) $val .= $_k . ':' . $_value . ', '; |
|
| 72 | + $val = substr($val, 0, -2); |
|
| 73 | 73 | } else $val = $value; |
| 74 | - $string .= $att.': "'.$val.'",'."\n"; |
|
| 74 | + $string .= $att . ': "' . $val . '",' . "\n"; |
|
| 75 | 75 | } |
| 76 | - $string = substr($string,0,-2)."\n"; |
|
| 77 | - $string .= '},'."\n"; |
|
| 76 | + $string = substr($string, 0, -2) . "\n"; |
|
| 77 | + $string .= '},' . "\n"; |
|
| 78 | 78 | } |
| 79 | - $string = substr($string,0,-2); |
|
| 79 | + $string = substr($string, 0, -2); |
|
| 80 | 80 | return $string; |
| 81 | 81 | } |
| 82 | 82 | else return false; |
@@ -92,18 +92,18 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @return number|string The sipping cost for the current cart |
| 94 | 94 | */ |
| 95 | - function get_shipping_cost( $nb_of_items, $total_cart, $total_shipping_cost, $total_weight, $selected_method = '' ) {
|
|
| 95 | + function get_shipping_cost($nb_of_items, $total_cart, $total_shipping_cost, $total_weight, $selected_method = '') {
|
|
| 96 | 96 | global $wpdb; |
| 97 | - $shipping_mode_option = get_option( 'wps_shipping_mode' ); |
|
| 98 | - if( !empty($selected_method) || isset( $_SESSION['shipping_address'] ) && empty( $_SESSION['shipping_method'] ) ) {
|
|
| 99 | - if( !empty($selected_method) ) {
|
|
| 97 | + $shipping_mode_option = get_option('wps_shipping_mode');
|
|
| 98 | + if (!empty($selected_method) || isset($_SESSION['shipping_address']) && empty($_SESSION['shipping_method'])) {
|
|
| 99 | + if (!empty($selected_method)) {
|
|
| 100 | 100 | $chosen_shipping_mode = $selected_method; |
| 101 | 101 | } else {
|
| 102 | 102 | $ship_mod = new wps_shipping_mode_ctr(); |
| 103 | - $shipping_modes = $ship_mod->get_shipping_mode_for_address( $_SESSION['shipping_address'] ); |
|
| 104 | - if( !empty( $shipping_modes ) ) {
|
|
| 103 | + $shipping_modes = $ship_mod->get_shipping_mode_for_address($_SESSION['shipping_address']); |
|
| 104 | + if (!empty($shipping_modes)) {
|
|
| 105 | 105 | $shipping_modes = $shipping_modes['modes']; |
| 106 | - foreach( $shipping_modes as $key => $shipping_mode ) {
|
|
| 106 | + foreach ($shipping_modes as $key => $shipping_mode) {
|
|
| 107 | 107 | $chosen_shipping_mode = $key; |
| 108 | 108 | break; |
| 109 | 109 | } |
@@ -113,37 +113,37 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | else {
|
| 116 | - if( !empty( $_SESSION['shipping_method'] ) ) {
|
|
| 117 | - $chosen_shipping_mode = wpshop_tools::varSanitizer( $_SESSION['shipping_method'] ); |
|
| 116 | + if (!empty($_SESSION['shipping_method'])) {
|
|
| 117 | + $chosen_shipping_mode = wpshop_tools::varSanitizer($_SESSION['shipping_method']); |
|
| 118 | 118 | } else {
|
| 119 | 119 | $chosen_shipping_mode = 'default_choice'; |
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $default_weight_unity = get_option( 'wpshop_shop_default_weight_unity' ); |
|
| 124 | - if ( !empty($default_weight_unity) ) {
|
|
| 125 | - $query = $wpdb->prepare('SELECT unit FROM ' .WPSHOP_DBT_ATTRIBUTE_UNIT. ' WHERE id = %d', $default_weight_unity);
|
|
| 126 | - $weight_unity = $wpdb->get_var( $query ); |
|
| 123 | + $default_weight_unity = get_option('wpshop_shop_default_weight_unity');
|
|
| 124 | + if (!empty($default_weight_unity)) {
|
|
| 125 | + $query = $wpdb->prepare('SELECT unit FROM ' . WPSHOP_DBT_ATTRIBUTE_UNIT . ' WHERE id = %d', $default_weight_unity);
|
|
| 126 | + $weight_unity = $wpdb->get_var($query); |
|
| 127 | 127 | |
| 128 | - if ( !empty($weight_unity) && $weight_unity == 'kg' ) {
|
|
| 128 | + if (!empty($weight_unity) && $weight_unity == 'kg') {
|
|
| 129 | 129 | |
| 130 | 130 | $total_weight = $total_weight * 1000; |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if ( ( !empty($_SESSION['shipping_method']) && $_SESSION['shipping_method'] == 'shipping-partners' ) || !empty( $_SESSION['wps-pos-addon']) ) {
|
|
| 134 | + if ((!empty($_SESSION['shipping_method']) && $_SESSION['shipping_method'] == 'shipping-partners') || !empty($_SESSION['wps-pos-addon'])) {
|
|
| 135 | 135 | return 0; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** Take the selected shipping mode **/ |
| 139 | - if( $chosen_shipping_mode == 'default_choice' ) {
|
|
| 140 | - if( !empty( $shipping_mode_option['modes'][$shipping_mode_option['default_choice']]) ) {
|
|
| 139 | + if ($chosen_shipping_mode == 'default_choice') {
|
|
| 140 | + if (!empty($shipping_mode_option['modes'][$shipping_mode_option['default_choice']])) {
|
|
| 141 | 141 | $selected_shipping_mode_config = $shipping_mode_option['modes'][$shipping_mode_option['default_choice']]; |
| 142 | 142 | } else {
|
| 143 | 143 | $selected_shipping_mode_config = ''; |
| 144 | 144 | } |
| 145 | 145 | } else {
|
| 146 | - if( !empty( $shipping_mode_option['modes'][$chosen_shipping_mode]) ) {
|
|
| 146 | + if (!empty($shipping_mode_option['modes'][$chosen_shipping_mode])) {
|
|
| 147 | 147 | $selected_shipping_mode_config = $shipping_mode_option['modes'][$chosen_shipping_mode]; |
| 148 | 148 | } else {
|
| 149 | 149 | $selected_shipping_mode_config = ''; |
@@ -155,41 +155,41 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | |
| 157 | 157 | /** Free Shipping **/ |
| 158 | - if ( ( !empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_shipping']) ) || ( $selected_method == 'is_downloadable_' ) ) {
|
|
| 158 | + if ((!empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_shipping'])) || ($selected_method == 'is_downloadable_')) {
|
|
| 159 | 159 | $shipping_cost = 0; |
| 160 | 160 | } |
| 161 | 161 | /** Free Shipping From **/ |
| 162 | - elseif( !empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_from']) && $selected_shipping_mode_config['free_from'] >= 0 && $selected_shipping_mode_config['free_from'] <= number_format( $total_cart, 2, '.', '') ) {
|
|
| 162 | + elseif (!empty($selected_shipping_mode_config) && !empty($selected_shipping_mode_config['free_from']) && $selected_shipping_mode_config['free_from'] >= 0 && $selected_shipping_mode_config['free_from'] <= number_format($total_cart, 2, '.', '')) {
|
|
| 163 | 163 | $shipping_cost = 0; |
| 164 | 164 | } |
| 165 | 165 | else {
|
| 166 | 166 | /** Check Custom Shipping Cost **/ |
| 167 | 167 | |
| 168 | - if ( !empty($selected_shipping_mode_config['custom_shipping_rules']) && !empty($selected_shipping_mode_config['custom_shipping_rules']['active']) ) {
|
|
| 168 | + if (!empty($selected_shipping_mode_config['custom_shipping_rules']) && !empty($selected_shipping_mode_config['custom_shipping_rules']['active'])) {
|
|
| 169 | 169 | $address_infos = ''; |
| 170 | - if( !empty( $_SESSION['shipping_address'] ) ) {
|
|
| 171 | - $address_infos = get_post_meta($_SESSION['shipping_address'],'_wpshop_address_metadata', true); |
|
| 170 | + if (!empty($_SESSION['shipping_address'])) {
|
|
| 171 | + $address_infos = get_post_meta($_SESSION['shipping_address'], '_wpshop_address_metadata', true); |
|
| 172 | 172 | } |
| 173 | - $country = ( !empty($address_infos['country']) ) ? $address_infos['country'] : ''; |
|
| 173 | + $country = (!empty($address_infos['country'])) ? $address_infos['country'] : ''; |
|
| 174 | 174 | /** Check Active Postcode option **/ |
| 175 | - if ( !empty($selected_shipping_mode_config['custom_shipping_rules']['active_cp']) ) {
|
|
| 175 | + if (!empty($selected_shipping_mode_config['custom_shipping_rules']['active_cp'])) {
|
|
| 176 | 176 | $postcode = $address_infos['postcode']; |
| 177 | - if ( array_key_exists($country.'-'.$postcode, $selected_shipping_mode_config['custom_shipping_rules']['fees']) ) {
|
|
| 178 | - $country = $country.'-'.$postcode; |
|
| 177 | + if (array_key_exists($country . '-' . $postcode, $selected_shipping_mode_config['custom_shipping_rules']['fees'])) {
|
|
| 178 | + $country = $country . '-' . $postcode; |
|
| 179 | 179 | } |
| 180 | - elseif( array_key_exists($country.'-OTHERS', $selected_shipping_mode_config['custom_shipping_rules']['fees']) ) {
|
|
| 181 | - $country = $country.'-OTHERS'; |
|
| 180 | + elseif (array_key_exists($country . '-OTHERS', $selected_shipping_mode_config['custom_shipping_rules']['fees'])) {
|
|
| 181 | + $country = $country . '-OTHERS'; |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | - $shipping_cost += $this->calculate_custom_shipping_cost($country, array('weight'=>$total_weight,'price'=> $total_cart), $selected_shipping_mode_config['custom_shipping_rules']['fees'], $chosen_shipping_mode);
|
|
| 184 | + $shipping_cost += $this->calculate_custom_shipping_cost($country, array('weight'=>$total_weight, 'price'=> $total_cart), $selected_shipping_mode_config['custom_shipping_rules']['fees'], $chosen_shipping_mode);
|
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** Min- Max config **/ |
| 188 | - if ( !empty($selected_shipping_mode_config['min_max']) && !empty($selected_shipping_mode_config['min_max']['activate']) ) {
|
|
| 189 | - if ( !empty($selected_shipping_mode_config['min_max']['min']) && $shipping_cost < $selected_shipping_mode_config['min_max']['min'] ) {
|
|
| 188 | + if (!empty($selected_shipping_mode_config['min_max']) && !empty($selected_shipping_mode_config['min_max']['activate'])) {
|
|
| 189 | + if (!empty($selected_shipping_mode_config['min_max']['min']) && $shipping_cost < $selected_shipping_mode_config['min_max']['min']) {
|
|
| 190 | 190 | $shipping_cost = $selected_shipping_mode_config['min_max']['min']; |
| 191 | 191 | } |
| 192 | - elseif( !empty($selected_shipping_mode_config['min_max']['max']) &&$shipping_cost > $selected_shipping_mode_config['min_max']['max']) {
|
|
| 192 | + elseif (!empty($selected_shipping_mode_config['min_max']['max']) && $shipping_cost > $selected_shipping_mode_config['min_max']['max']) {
|
|
| 193 | 193 | $shipping_cost = $selected_shipping_mode_config['min_max']['max']; |
| 194 | 194 | } |
| 195 | 195 | |
@@ -207,40 +207,40 @@ discard block |
||
| 207 | 207 | * @param array $fees |
| 208 | 208 | * @return number|boolean|Ambigous <number, unknown> |
| 209 | 209 | */ |
| 210 | - function calculate_custom_shipping_cost($dest='', $data, $fees, $shipping_method = false) {
|
|
| 210 | + function calculate_custom_shipping_cost($dest = '', $data, $fees, $shipping_method = false) {
|
|
| 211 | 211 | $fees_table = array(); |
| 212 | 212 | $key = ''; $price = 0; |
| 213 | 213 | |
| 214 | - if ( !empty($_SESSION['shipping_partner_id']) ) {
|
|
| 214 | + if (!empty($_SESSION['shipping_partner_id'])) {
|
|
| 215 | 215 | return 0; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if($shipping_method === false) {
|
|
| 218 | + if ($shipping_method === false) {
|
|
| 219 | 219 | $shipping_method = $_SESSION['shipping_method']; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if(!empty($fees) || !empty($dest) ) {
|
|
| 223 | - $custom_shipping_option = get_option( 'wpshop_custom_shipping', true ); |
|
| 224 | - $shipping_modes = get_option( 'wps_shipping_mode' ); |
|
| 222 | + if (!empty($fees) || !empty($dest)) {
|
|
| 223 | + $custom_shipping_option = get_option('wpshop_custom_shipping', true);
|
|
| 224 | + $shipping_modes = get_option('wps_shipping_mode');
|
|
| 225 | 225 | |
| 226 | - if ( !empty($shipping_method) ) {
|
|
| 227 | - if ( !empty($shipping_modes) && !empty($shipping_modes['modes']) && !empty($shipping_modes['modes'][ $shipping_method ]) ) {
|
|
| 228 | - $custom_shipping_option = $shipping_modes['modes'][ $shipping_method ]['custom_shipping_rules']; |
|
| 226 | + if (!empty($shipping_method)) {
|
|
| 227 | + if (!empty($shipping_modes) && !empty($shipping_modes['modes']) && !empty($shipping_modes['modes'][$shipping_method])) {
|
|
| 228 | + $custom_shipping_option = $shipping_modes['modes'][$shipping_method]['custom_shipping_rules']; |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | $found_active_cp_rule = $found_active_departement_rule = false; |
| 232 | - $shipping_address_def = get_post_meta( $_SESSION['shipping_address'], '_wpshop_address_metadata', true ); |
|
| 232 | + $shipping_address_def = get_post_meta($_SESSION['shipping_address'], '_wpshop_address_metadata', true); |
|
| 233 | 233 | $postcode = ''; |
| 234 | - if ( !empty($shipping_address_def) ) {
|
|
| 234 | + if (!empty($shipping_address_def)) {
|
|
| 235 | 235 | $postcode = $shipping_address_def['postcode']; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** Search Postcode custom fees **/ |
| 239 | - if ( !empty($custom_shipping_option) && !empty($custom_shipping_option['active_cp']) ) {
|
|
| 240 | - $key = $dest.'-'.$postcode; |
|
| 241 | - if ( array_key_exists($key, $fees) ) {
|
|
| 239 | + if (!empty($custom_shipping_option) && !empty($custom_shipping_option['active_cp'])) {
|
|
| 240 | + $key = $dest . '-' . $postcode; |
|
| 241 | + if (array_key_exists($key, $fees)) {
|
|
| 242 | 242 | foreach ($fees[$key]['fees'] as $k => $shipping_price) {
|
| 243 | - if ( $data['weight'] <= $k) {
|
|
| 243 | + if ($data['weight'] <= $k) {
|
|
| 244 | 244 | break; |
| 245 | 245 | } |
| 246 | 246 | } |
@@ -249,13 +249,13 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** Search Department custom fees **/ |
| 252 | - if( !empty($custom_shipping_option) && !empty($custom_shipping_option['active_department']) && !$found_active_cp_rule ) {
|
|
| 253 | - $department = substr( $postcode, 0,2 ); |
|
| 254 | - $key = $dest.'-'.$department; |
|
| 252 | + if (!empty($custom_shipping_option) && !empty($custom_shipping_option['active_department']) && !$found_active_cp_rule) {
|
|
| 253 | + $department = substr($postcode, 0, 2); |
|
| 254 | + $key = $dest . '-' . $department; |
|
| 255 | 255 | /** Check if a rule exists **/ |
| 256 | - if ( array_key_exists($key, $fees) ) {
|
|
| 256 | + if (array_key_exists($key, $fees)) {
|
|
| 257 | 257 | foreach ($fees[$key]['fees'] as $k => $shipping_price) {
|
| 258 | - if ( $data['weight'] <= $k) {
|
|
| 258 | + if ($data['weight'] <= $k) {
|
|
| 259 | 259 | break; |
| 260 | 260 | } |
| 261 | 261 | } |
@@ -264,11 +264,11 @@ discard block |
||
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** Search general custom fees **/ |
| 267 | - if( !$found_active_cp_rule && !$found_active_departement_rule ){
|
|
| 268 | - if ( array_key_exists($dest, $fees) ) {
|
|
| 267 | + if (!$found_active_cp_rule && !$found_active_departement_rule) {
|
|
| 268 | + if (array_key_exists($dest, $fees)) {
|
|
| 269 | 269 | $key = $dest; |
| 270 | 270 | } |
| 271 | - elseif( array_key_exists( 'OTHERS', $fees) ) {
|
|
| 271 | + elseif (array_key_exists('OTHERS', $fees)) {
|
|
| 272 | 272 | $key = 'OTHERS'; |
| 273 | 273 | } |
| 274 | 274 | else {
|
@@ -277,10 +277,10 @@ discard block |
||
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | //Search fees |
| 280 | - if ( !empty($key) ) {
|
|
| 281 | - ksort( $fees[$key]['fees'] ); |
|
| 280 | + if (!empty($key)) {
|
|
| 281 | + ksort($fees[$key]['fees']); |
|
| 282 | 282 | foreach ($fees[$key]['fees'] as $k => $shipping_price) {
|
| 283 | - if ( $data['weight'] <= $k) {
|
|
| 283 | + if ($data['weight'] <= $k) {
|
|
| 284 | 284 | $price = $shipping_price; |
| 285 | 285 | break; |
| 286 | 286 | } |
@@ -302,14 +302,14 @@ discard block |
||
| 302 | 302 | * @param array $cart_items |
| 303 | 303 | * @return number |
| 304 | 304 | */ |
| 305 | - function calcul_cart_items_shipping_cost( $cart_items ) {
|
|
| 305 | + function calcul_cart_items_shipping_cost($cart_items) {
|
|
| 306 | 306 | $shipping_cost = 0; |
| 307 | - if( !empty($cart_items) ) {
|
|
| 308 | - foreach( $cart_items as $cart_item ) {
|
|
| 309 | - $product_data = get_post_meta( $cart_item['item_id'], '_wpshop_product_metadata', true ); |
|
| 307 | + if (!empty($cart_items)) {
|
|
| 308 | + foreach ($cart_items as $cart_item) {
|
|
| 309 | + $product_data = get_post_meta($cart_item['item_id'], '_wpshop_product_metadata', true); |
|
| 310 | 310 | |
| 311 | - if ( !empty( $product_data ) && !empty( $product_data['cost_of_postage'] ) ) {
|
|
| 312 | - $shipping_cost += ( $product_data['cost_of_postage'] * $cart_item['item_qty'] ); |
|
| 311 | + if (!empty($product_data) && !empty($product_data['cost_of_postage'])) {
|
|
| 312 | + $shipping_cost += ($product_data['cost_of_postage'] * $cart_item['item_qty']); |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | } |
@@ -322,32 +322,32 @@ discard block |
||
| 322 | 322 | * @param array $cart_items |
| 323 | 323 | * @return number |
| 324 | 324 | */ |
| 325 | - function calcul_cart_weight( $cart_items ) {
|
|
| 325 | + function calcul_cart_weight($cart_items) {
|
|
| 326 | 326 | $cart_weight = 0; |
| 327 | - if ( !empty( $cart_items) ) {
|
|
| 328 | - foreach( $cart_items as $id_item => $cart_item ) {
|
|
| 327 | + if (!empty($cart_items)) {
|
|
| 328 | + foreach ($cart_items as $id_item => $cart_item) {
|
|
| 329 | 329 | $id_item = wpshop_products::get_id_variation($id_item); |
| 330 | - if ( get_post_type($id_item) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION ) {
|
|
| 331 | - $product_data = get_post_meta( $id_item, '_wpshop_product_metadata', true ); |
|
| 332 | - if ( !empty($product_data) && !empty($product_data['product_weight']) ) {
|
|
| 333 | - $cart_weight += ( $product_data['product_weight'] * $cart_item['item_qty'] ); |
|
| 330 | + if (get_post_type($id_item) == WPSHOP_NEWTYPE_IDENTIFIER_PRODUCT_VARIATION) {
|
|
| 331 | + $product_data = get_post_meta($id_item, '_wpshop_product_metadata', true); |
|
| 332 | + if (!empty($product_data) && !empty($product_data['product_weight'])) {
|
|
| 333 | + $cart_weight += ($product_data['product_weight'] * $cart_item['item_qty']); |
|
| 334 | 334 | } |
| 335 | 335 | else {
|
| 336 | - $parent_def = wpshop_products::get_parent_variation( $id_item ); |
|
| 337 | - if ( !empty($parent_def) && !empty( $parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['product_weight']) ) {
|
|
| 338 | - $cart_weight += ( $parent_def['parent_post_meta']['product_weight'] * $cart_item['item_qty'] ); |
|
| 336 | + $parent_def = wpshop_products::get_parent_variation($id_item); |
|
| 337 | + if (!empty($parent_def) && !empty($parent_def['parent_post_meta']) && !empty($parent_def['parent_post_meta']['product_weight'])) {
|
|
| 338 | + $cart_weight += ($parent_def['parent_post_meta']['product_weight'] * $cart_item['item_qty']); |
|
| 339 | 339 | } |
| 340 | 340 | } |
| 341 | 341 | } |
| 342 | 342 | else {
|
| 343 | - $product_data = get_post_meta( $cart_item['item_id'], '_wpshop_product_metadata', true ); |
|
| 344 | - if ( !empty($product_data) && !empty($product_data['product_weight']) && !empty($cart_item['item_qty']) ) {
|
|
| 345 | - $cart_weight += ( $product_data['product_weight'] * $cart_item['item_qty'] ); |
|
| 343 | + $product_data = get_post_meta($cart_item['item_id'], '_wpshop_product_metadata', true); |
|
| 344 | + if (!empty($product_data) && !empty($product_data['product_weight']) && !empty($cart_item['item_qty'])) {
|
|
| 345 | + $cart_weight += ($product_data['product_weight'] * $cart_item['item_qty']); |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | - $cart_weight = apply_filters( 'extra_cart_weight_calcul', $cart_weight, $cart_items ); |
|
| 350 | + $cart_weight = apply_filters('extra_cart_weight_calcul', $cart_weight, $cart_items);
|
|
| 351 | 351 | return $cart_weight; |
| 352 | 352 | } |
| 353 | 353 | |