Changeset 3435849
- Timestamp:
- 01/09/2026 11:35:18 AM (3 months ago)
- Location:
- wpos-lite-version
- Files:
-
- 9 edited
-
tags/3.0/includes/Core.php (modified) (1 diff)
-
tags/3.1/includes/Core.php (modified) (1 diff)
-
tags/3.1/readme.txt (modified) (1 diff)
-
trunk/includes/Core.php (modified) (10 diffs)
-
trunk/includes/api/Auth.php (modified) (2 diffs)
-
trunk/includes/api/Cart.php (modified) (12 diffs)
-
trunk/index.php (modified) (1 diff)
-
trunk/lib/class-op-woo-cart.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wpos-lite-version/tags/3.0/includes/Core.php
r3377825 r3435849 2161 2161 function get_pos_url($sub_str = ''){ 2162 2162 2163 $pos_url = apply_filters('op_pos_url',WPOSL_URL.'/pos/'); 2164 if($sub_str) 2165 { 2166 $pos_url = trim(rtrim($pos_url,'/')); 2167 2168 $pos_url .= '/'.$sub_str; 2169 } 2163 $pos_url = apply_filters('op_pos_url','https://pos.wpos.app/#/'); 2164 2165 2170 2166 return $pos_url; 2171 2167 } -
wpos-lite-version/tags/3.1/includes/Core.php
r3377906 r3435849 2161 2161 function get_pos_url($sub_str = ''){ 2162 2162 2163 $pos_url = apply_filters('op_pos_url',WPOSL_URL.'/pos/'); 2164 if($sub_str) 2165 { 2166 $pos_url = trim(rtrim($pos_url,'/')); 2167 2168 $pos_url .= '/'.$sub_str; 2169 } 2163 $pos_url = apply_filters('op_pos_url','https://pos.wpos.app/#/'); 2164 2165 2170 2166 return $pos_url; 2171 2167 } -
wpos-lite-version/tags/3.1/readme.txt
r3377296 r3435849 39 39 40 40 🎥 Watch the demo video: 41 https:// www.youtube.com/watch?v=dQw4w9WgXcQ41 https://youtu.be/zqCd4Ox3NIk?si=CUv6q0m76N4inOMM 42 42 43 43 --- -
wpos-lite-version/trunk/includes/Core.php
r3376736 r3435849 49 49 $locale = determine_locale(); 50 50 unload_textdomain( 'openpos', true ); 51 load_textdomain( 'openpos', trailingslashit( OPENPOS_DIR).'languages/openpos-' . $locale . '.mo' );52 load_plugin_textdomain( 'openpos', false, trailingslashit( OPENPOS_DIR).'languages/' );51 load_textdomain( 'openpos', trailingslashit(WPOSL_DIR).'languages/openpos-' . $locale . '.mo' ); 52 load_plugin_textdomain( 'openpos', false, trailingslashit(WPOSL_DIR).'languages/' ); 53 53 //end 54 54 } … … 104 104 } 105 105 public function getPluginInfo(){ 106 $this->plugin_info = get_plugin_data( OPENPOS_DIR.'woocommerce-openpos.php');106 $this->plugin_info = get_plugin_data(WPOSL_DIR.'index.php'); 107 107 return $this->plugin_info; 108 108 } … … 1856 1856 1857 1857 1858 $file_path = rtrim( OPENPOS_DIR,'/').'/default/'.$file_name;1858 $file_path = rtrim(WPOSL_DIR,'/').'/default/'.$file_name; 1859 1859 1860 1860 $theme_file_path = rtrim(get_stylesheet_directory(),'/').'/woocommerce-openpos/'.$file_name; … … 1866 1866 { 1867 1867 $file_name = 'receipt_incl_tax_template_body.txt'; 1868 $file_path = rtrim( OPENPOS_DIR,'/').'/default/'.$file_name;1868 $file_path = rtrim(WPOSL_DIR,'/').'/default/'.$file_name; 1869 1869 } 1870 1870 } 1871 1871 $_gift_file_name = 'receipt_gift_template_body.txt'; 1872 $gift_file_path = rtrim( OPENPOS_DIR,'/').'/default/'.$_gift_file_name;1872 $gift_file_path = rtrim(WPOSL_DIR,'/').'/default/'.$_gift_file_name; 1873 1873 1874 1874 $gift_theme_file_path = rtrim(get_stylesheet_directory(),'/').'/woocommerce-openpos/'.$_gift_file_name; … … 2039 2039 public function getReceiptFontCss(){ 2040 2040 $font_css = array(); 2041 $font_css['receipt_font'] = OPENPOS_URL.'/pos/font.css';2041 $font_css['receipt_font'] = WPOSL_URL.'/pos/font.css'; 2042 2042 return $font_css; 2043 2043 } … … 2161 2161 function get_pos_url($sub_str = ''){ 2162 2162 2163 $pos_url = apply_filters('op_pos_url',OPENPOS_URL.'/pos/'); 2164 if($sub_str) 2165 { 2166 $pos_url = trim(rtrim($pos_url,'/')); 2167 2168 $pos_url .= '/'.$sub_str; 2169 } 2163 $pos_url = apply_filters('op_pos_url','https://pos.wpos.app/#/'); 2164 2165 2170 2166 return $pos_url; 2171 2167 } 2172 2168 function get_kitchen_url($wareshouse_id = 0,$base = false){ 2173 2169 2174 $pos_url = apply_filters('op_kitchen_url', OPENPOS_URL.'/kitchen/');2170 $pos_url = apply_filters('op_kitchen_url',WPOSL_URL.'/kitchen/'); 2175 2171 2176 2172 if(!$base) … … 2190 2186 function get_bill_url($register_id = 0,$base = false){ 2191 2187 2192 $pos_url = apply_filters('op_bill_url', OPENPOS_URL.'/bill/');2188 $pos_url = apply_filters('op_bill_url',WPOSL_URL.'/bill/'); 2193 2189 2194 2190 if(!$base) … … 2208 2204 } 2209 2205 function get_customer_url($params = array()){ 2210 $customer_url = apply_filters('op_customer_url', OPENPOS_URL.'/customer/');2206 $customer_url = apply_filters('op_customer_url',WPOSL_URL.'/customer/'); 2211 2207 if(!empty($params)) 2212 2208 { … … 2263 2259 } 2264 2260 function getTemplatePath($file_name){ 2265 #$templath_path = OPENPOS_DIR.'templates/emails/';2266 2261 $templath_dir = 'woocommerce-openpos/'; 2267 2262 $check_dirs = array( … … 2270 2265 trailingslashit( get_stylesheet_directory() ), 2271 2266 trailingslashit( get_template_directory() ), 2272 trailingslashit( OPENPOS_DIR ) . 'templates/',2267 trailingslashit( WPOSL_DIR ) . 'templates/', 2273 2268 ); 2274 2269 foreach ( $check_dirs as $dir ) { -
wpos-lite-version/trunk/includes/api/Auth.php
r3376736 r3435849 505 505 $setting['pos_disable_item_discount'] = 'yes'; 506 506 $setting['pos_disable_cart_discount'] = 'yes'; 507 $setting['pos_cart_tab'] = 'no'; // disable multi tab login for customer mode and waiter mode 507 508 $setting['pos_cart_buttons'] = array( 508 509 'cart-note', … … 560 561 $setting['pos_weight_barcode_prefix'] = '20'; 561 562 } 563 564 562 565 563 566 $session_data['setting'] = $setting; -
wpos-lite-version/trunk/includes/api/Cart.php
r3372360 r3435849 81 81 if(!$register_id ) 82 82 { 83 throw new Exception(__('Register not found',' wpos-lite'));83 throw new Exception(__('Register not found','openpos')); 84 84 } 85 85 $warehouse_meta_key = $this->warehouse_class->get_order_meta_key(); … … 135 135 136 136 }else{ 137 throw new Exception(__('No cart found',' wpos-lite'));137 throw new Exception(__('No cart found','openpos')); 138 138 } 139 139 $result['response']['data'] = $carts; … … 163 163 if(!$order_number) 164 164 { 165 throw new Exception( __('Cart Not found',' wpos-lite') );165 throw new Exception( __('Cart Not found','openpos') ); 166 166 }else{ 167 167 if(!$this->core_class->enable_hpos()) … … 177 177 if(!$order) 178 178 { 179 throw new Exception( __('Cart Not found',' wpos-lite') );179 throw new Exception( __('Cart Not found','openpos') ); 180 180 } 181 181 $cart_data = get_post_meta($order->ID,'_op_cart_data'); … … 192 192 if(!$cart_data || !is_array($cart_data) || empty($cart_data)) 193 193 { 194 throw new Exception( __('Cart Not found',' wpos-lite') );194 throw new Exception( __('Cart Not found','openpos') ); 195 195 }else{ 196 196 $result['response']['data'] = $cart_data; … … 264 264 }else{ 265 265 266 throw new Exception(__('Cart Not Found', ' wpos-lite'));266 throw new Exception(__('Cart Not Found', 'openpos')); 267 267 } 268 268 … … 295 295 if(!isset($register['id'])) 296 296 { 297 throw new Exception(__('Register not found',' wpos-lite'));297 throw new Exception(__('Register not found','openpos')); 298 298 } 299 299 $register_id = $register['id']; … … 430 430 431 431 $result['response']['status'] = 1; 432 $result['response']['data'] = $this->cart_class->getShippingMethod($by_data,$cart );432 $result['response']['data'] = $this->cart_class->getShippingMethod($by_data,$cart,true); 433 433 434 434 do_action('op_get_online_shipping_method',$result,$session_data); … … 468 468 { 469 469 $result['response']['status'] = 1; 470 $cost = $this->cart_class->getShippingCost($by_data,$cart );470 $cost = $this->cart_class->getShippingCost($by_data,$cart,true); 471 471 if(!empty($cost)) 472 472 { … … 555 555 if($a_coupon->get_individual_use()) 556 556 { 557 throw new Exception(sprintf(__('Coupon %s is invidual use',' wpos-lite'),$_a['code']));557 throw new Exception(sprintf(__('Coupon %s is invidual use','openpos'),$_a['code'])); 558 558 } 559 559 } … … 629 629 if($amount < 0) 630 630 { 631 $msg = __('Coupon code has been expired',' wpos-lite');631 $msg = __('Coupon code has been expired','openpos'); 632 632 throw new Exception($msg ); 633 633 } … … 681 681 } 682 682 683 $result['response']['message'] = sprintf(__("<b>%s</b> discount value: <b>%s</b>", ' wpos-lite'), $code,$string_amnt);683 $result['response']['message'] = sprintf(__("<b>%s</b> discount value: <b>%s</b>", 'openpos'), $code,$string_amnt); 684 684 $result['response']['status'] = 1; 685 685 -
wpos-lite-version/trunk/index.php
r3372171 r3435849 6 6 Author: anhvnit@gmail.com 7 7 Author URI: http://openswatch.com/ 8 Version: 3. 08 Version: 3.1 9 9 WC requires at least: 2.6 10 10 WC tested up to: 4.8.0 -
wpos-lite-version/trunk/lib/class-op-woo-cart.php
r3372171 r3435849 125 125 return $cart_data; 126 126 } 127 public function getShippingMethod($shipping_data,$cart_data ){127 public function getShippingMethod($shipping_data,$cart_data,$is_api=false){ 128 128 global $op_woo; 129 129 do_action('op_get_shipping_method_before',$shipping_data,$cart_data); … … 140 140 $country = $store_country; 141 141 } 142 $methods_rates = array(); 143 if(!$is_api) 144 { 145 WC()->cart->empty_cart(); 146 WC()->session->cleanup_sessions(); 147 $cart = new WC_Cart(); 148 149 $items = $cart_data['items']; 150 foreach($items as $item) 151 { 152 $product_id = isset($item['product_id']) ? $item['product_id'] : 0; 153 $product_qty = isset($item['qty']) ? $item['qty'] : 0; 154 155 if($product_id && $product_qty) 156 { 157 $_product = wc_get_product($product_id); 158 159 if($_product) 160 { 161 $parent_id = $product_id; 162 $variation_id = 0; 163 if($_product->get_type() == 'variation') 164 { 165 $parent_id = $_product->get_parent_id(); 166 $variation_id = $product_id; 167 } 168 try{ 169 170 $cart->add_to_cart($parent_id,$product_qty,$variation_id); 171 172 }catch (Exception $e) 173 { 174 print_r($e);die; 175 } 176 } 177 } 178 } 179 180 181 $cart->calculate_totals(); 182 183 $customer = $cart->get_customer(); 184 $customer->set_shipping_state($state); 185 $customer->set_shipping_address($address); 186 $customer->set_shipping_postcode($postcode); 187 $customer->set_shipping_address_2($address_2); 188 $customer->set_shipping_country($country); 189 $customer->set_shipping_city($city); 190 191 $customer->set_billing_state($state); 192 $customer->set_billing_address($address); 193 $customer->set_billing_postcode($postcode); 194 $customer->set_billing_address_2($address_2); 195 $customer->set_billing_country($country); 196 $customer->set_billing_city($city); 197 198 $customer->set_calculated_shipping(false); 199 $cart->calculate_shipping(); 200 $packages = WC()->shipping()->get_packages(); 201 202 203 204 foreach($packages as $package) 205 { 206 $package_rates = $package['rates']; 207 foreach($package_rates as $package_rate) 208 { 209 $id = $package_rate->get_id(); 210 $cost = $package_rate->get_cost(); 211 if(!$cost) 212 { 213 $cost = 0; 214 } 215 $tax = $package_rate->get_shipping_tax(); 216 $label = $package_rate->get_label(); 217 $tmp = array( 218 'code' => $id, 219 'label' => $label, 220 'title' => sprintf('%s (%s : %s)',$label,__('Cost','openpos'),strip_tags(wc_price($cost+ $tax))), 221 'cost' => $cost, 222 'tax' => $tax, 223 ); 224 $methods_rates[$id] = $tmp; 225 } 226 } 227 do_action('op_get_shipping_method_after',$shipping_data,$cart_data); 228 WC()->session->cleanup_sessions(); 229 WC()->cart->empty_cart(); 230 }else{ 231 232 if (isset($cart_data['items']) && !empty($cart_data['items'])) { 233 $package = array( 234 'contents' => array(), 235 'contents_cost' => 0, 236 'applied_coupons' => array(), 237 'destination' => array( 238 'country' => $country, 239 'state' => $state, 240 'postcode' => $postcode, 241 'city' => $city, 242 'address' => $address, 243 'address_2' => $address_2, 244 ), 245 ); 246 247 248 foreach ($cart_data['items'] as $item) { 249 $product_id = isset($item['product_id']) ? $item['product_id'] : 0; 250 $qty = isset($item['qty']) ? $item['qty'] : 1; 251 if ($product_id && $qty) { 252 $product = wc_get_product($product_id); 253 if ($product) { 254 $package['contents'][$product_id] = array( 255 'product_id' => $product_id, 256 'data' => $product, 257 'quantity' => $qty, 258 'line_total' => $item['final_price'] * $qty, 259 'line_tax' => $item['total_tax'] , 260 ); 261 $package['contents_cost'] += $item['total']; 262 }else{ 263 $package['contents'][$product_id] = array( 264 'product_id' => $product_id, 265 'data' => array(), 266 'quantity' => $qty, 267 'line_total' => $item['final_price'] * $qty, 268 'line_tax' => $item['total_tax'] , 269 ); 270 $package['contents_cost'] += $item['total']; 271 } 272 } 273 } 274 275 $methods_rates = $this->get_available_shipping_methods($package['destination'], $package['contents']); 276 277 278 } 279 } 280 281 return apply_filters('op_shipping_method_data',array_values($methods_rates)); 282 } 283 function get_available_shipping_methods( $address, $cart_items ) { 284 142 285 WC()->cart->empty_cart(); 143 WC()->session->cleanup_sessions(); 144 $cart = new WC_Cart(); 145 146 $items = $cart_data['items']; 147 foreach($items as $item) 148 { 149 $product_id = isset($item['product_id']) ? $item['product_id'] : 0; 150 $product_qty = isset($item['qty']) ? $item['qty'] : 0; 151 152 if($product_id && $product_qty) 153 { 154 $_product = wc_get_product($product_id); 286 287 288 foreach ( $cart_items as $item ) { 289 WC()->cart->add_to_cart( $item['product_id'], $item['quantity'] ); 290 } 291 $packages = [ 292 [ 293 'contents' => WC()->cart->get_cart(), 294 'contents_cost' => WC()->cart->get_cart_contents_total(), 295 'applied_coupons' => WC()->cart->get_applied_coupons(), 296 'user' => [ 297 'ID' => get_current_user_id(), 298 ], 299 'destination' => [ 300 'country' => $address['country'], 301 'state' => $address['state'], 302 'postcode' => $address['postcode'], 303 'city' => $address['city'], 304 'address' => $address['address_1'], 305 'address_2' => $address['address_2'] ?? '', 306 ], 307 ] 308 ]; 309 $shipping = new WC_Shipping(); 310 $shipping->calculate_shipping( $packages ); 311 312 $available_methods = []; 313 314 foreach ( $shipping->get_packages() as $package ) { 315 foreach ( $package['rates'] as $rate_id => $rate ) { 316 155 317 156 if($_product) 157 { 158 $parent_id = $product_id; 159 $variation_id = 0; 160 if($_product->get_type() == 'variation') 161 { 162 $parent_id = $_product->get_parent_id(); 163 $variation_id = $product_id; 164 } 165 try{ 166 167 $cart->add_to_cart($parent_id,$product_qty,$variation_id); 168 169 }catch (Exception $e) 170 { 171 print_r($e);die; 172 } 173 } 174 } 175 } 176 177 178 $cart->calculate_totals(); 179 180 $customer = $cart->get_customer(); 181 $customer->set_shipping_state($state); 182 $customer->set_shipping_address($address); 183 $customer->set_shipping_postcode($postcode); 184 $customer->set_shipping_address_2($address_2); 185 $customer->set_shipping_country($country); 186 $customer->set_shipping_city($city); 187 188 $customer->set_billing_state($state); 189 $customer->set_billing_address($address); 190 $customer->set_billing_postcode($postcode); 191 $customer->set_billing_address_2($address_2); 192 $customer->set_billing_country($country); 193 $customer->set_billing_city($city); 194 195 $customer->set_calculated_shipping(false); 196 $cart->calculate_shipping(); 197 $packages = WC()->shipping()->get_packages(); 198 $methods_rates = array(); 199 200 201 foreach($packages as $package) 202 { 203 $package_rates = $package['rates']; 204 foreach($package_rates as $package_rate) 205 { 206 $id = $package_rate->get_id(); 207 $cost = $package_rate->get_cost(); 208 if(!$cost) 209 { 210 $cost = 0; 211 } 212 $tax = $package_rate->get_shipping_tax(); 213 $label = $package_rate->get_label(); 214 $tmp = array( 215 'code' => $id, 216 'label' => $label, 217 'title' => sprintf('%s (%s : %s)',$label,__('Cost','wpos-lite'),strip_tags(wc_price($cost+ $tax))), 218 'cost' => $cost, 318 $tax = method_exists($rate, 'get_shipping_tax') ? $rate->get_shipping_tax() : 0; 319 $label = $rate->get_label(); 320 $cost = (float) $rate->get_cost(); 321 $available_methods[$rate_id] = [ 322 'code' => $rate_id, 323 'id' => $rate_id, 324 'label' => $rate->get_label(), 325 'cost' => (float) $rate->get_cost(), 219 326 'tax' => $tax, 220 ); 221 $methods_rates[$id] = $tmp; 222 } 223 } 224 do_action('op_get_shipping_method_after',$shipping_data,$cart_data); 225 WC()->session->cleanup_sessions(); 226 WC()->cart->empty_cart(); 227 return apply_filters('op_shipping_method_data',array_values($methods_rates)); 228 } 229 public function getShippingCost($shipping_data,$cart_data){ 327 'title' => sprintf('%s (%s : %s)',$label,__('Cost','openpos'),strip_tags(wc_price($cost+ $tax))), 328 ]; 329 } 330 } 331 332 return $available_methods; 333 } 334 335 public function getShippingCost($shipping_data,$cart_data,$is_rest = false){ 230 336 global $op_woo; 231 337 $address = isset($shipping_data['']) ? $shipping_data['address'] : ''; … … 241 347 $country = $store_country; 242 348 } 243 $session = WC()->session;244 $cart = new WC_Cart();245 246 $items = $cart_data['items'];247 foreach($items as $item)248 {249 $product_id = isset($item['product_id']) ? $item['product_id'] : 0;250 $product_qty = isset($item['qty']) ? $item['qty'] : 0;251 if($product_id && $product_qty)252 {253 $cart->add_to_cart($product_id,$product_qty);254 }255 }256 $cart->calculate_totals();257 $shipping_method = $shipping_data['shipping_method'];258 $customer = $cart->get_customer();259 $customer->set_shipping_state($state);260 $customer->set_shipping_address($address);261 $customer->set_shipping_postcode($postcode);262 $customer->set_shipping_address_2($address_2);263 $customer->set_shipping_country($country);264 $customer->set_shipping_city($city);265 $customer->set_calculated_shipping(false);266 $cart->calculate_shipping();267 $packages = WC()->shipping()->get_packages();268 349 $shipping_cost = array(); 269 350 $shipping_tax = array(); 270 351 $shipping_methods = array(); 271 foreach($packages as $package) 272 { 273 $package_rates = $package['rates']; 274 foreach($package_rates as $package_rate) 275 { 276 277 $method_id = $package_rate->method_id; 278 if($method_id == $shipping_method) 279 { 280 $shipping_methods[] = $package_rate; 281 } 282 } 283 } 352 if(!$is_rest) 353 { 354 $session = WC()->session; 355 $cart = new WC_Cart(); 356 357 $items = $cart_data['items']; 358 foreach($items as $item) 359 { 360 $product_id = isset($item['product_id']) ? $item['product_id'] : 0; 361 $product_qty = isset($item['qty']) ? $item['qty'] : 0; 362 if($product_id && $product_qty) 363 { 364 $cart->add_to_cart($product_id,$product_qty); 365 } 366 } 367 $cart->calculate_totals(); 368 $shipping_method = $shipping_data['shipping_method']; 369 $customer = $cart->get_customer(); 370 $customer->set_shipping_state($state); 371 $customer->set_shipping_address($address); 372 $customer->set_shipping_postcode($postcode); 373 $customer->set_shipping_address_2($address_2); 374 $customer->set_shipping_country($country); 375 $customer->set_shipping_city($city); 376 $customer->set_calculated_shipping(false); 377 $cart->calculate_shipping(); 378 $packages = WC()->shipping()->get_packages(); 379 380 foreach($packages as $package) 381 { 382 $package_rates = $package['rates']; 383 foreach($package_rates as $package_rate) 384 { 385 386 $method_id = $package_rate->method_id; 387 if($method_id == $shipping_method) 388 { 389 $shipping_methods[] = $package_rate; 390 } 391 } 392 } 393 }else{ 394 //rest api calc shipping method 395 } 396 284 397 foreach($shipping_methods as $shipping_method) 285 398 { … … 312 425 return array(); 313 426 } 314 public function getCartDiscount($cart_data ){427 public function getCartDiscount($cart_data,$is_api = false){ 315 428 $result = array(); 316 $session = WC()->session; 317 $cart = new WC_Cart(); 429 318 430 $customer_data = $cart_data['customer']; 319 320 if(!empty($customer_data)) { 321 322 if ($customer_data['id'] && $customer_data['id'] > 0) { 323 wp_set_current_user($customer_data['id']); 324 } 325 326 } 327 $items = $cart_data['items']; 328 foreach($items as $item) 329 { 330 $product_id = isset($item['product_id']) ? $item['product_id'] : 0; 331 $product_qty = isset($item['qty']) ? $item['qty'] : 0; 332 if($product_id && $product_qty) 333 { 334 $cart->add_to_cart($product_id,$product_qty); 335 } 336 } 337 338 $post_customer_data = array(); 339 if(!empty($customer_data)) 340 { 341 $customer = $cart->get_customer(); 342 343 344 if(isset($customer_data['email']) && $customer_data['email']) 345 { 346 $customer->set_email($customer_data['email']); 347 $post_customer_data['billing_email'] = $customer_data['email']; 348 } 349 if(isset($customer_data['firstname']) && $customer_data['firstname']) 350 { 351 $customer->set_first_name($customer_data['firstname']); 352 $post_customer_data['billing_first_name'] = $customer_data['firstname']; 353 } 354 if(isset($customer_data['lastname']) && $customer_data['lastname']) 355 { 356 $customer->set_last_name($customer_data['lastname']); 357 $post_customer_data['billing_last_name'] = $customer_data['lastname']; 358 } 359 if($customer_data['address']) 360 { 361 $customer->set_address($customer_data['address']); 362 $post_customer_data['billing_address_1'] = $customer_data['address']; 363 } 364 365 if(isset($customer_data['address_2']) && $customer_data['address_2']) 366 { 367 $customer->set_address_2($customer_data['address_2']); 368 $post_customer_data['billing_address_2'] = $customer_data['address_2']; 369 } 370 371 if(isset($customer_data['state']) && $customer_data['state']) 372 { 373 $customer->set_state($customer_data['state']); 374 $post_customer_data['billing_state'] = $customer_data['state']; 375 } 376 377 if(isset($customer_data['city']) && $customer_data['city']) 378 { 379 $customer->set_city($customer_data['city']); 380 $post_customer_data['billing_city'] = $customer_data['city']; 381 } 382 383 if(isset($customer_data['country']) && $customer_data['country']) 384 { 385 $customer->set_country($customer_data['country']); 386 $post_customer_data['billing_country'] = $customer_data['country']; 387 } 388 389 if(isset($customer_data['postcode']) && $customer_data['postcode']) 390 { 391 $customer->set_postcode($customer_data['postcode']); 392 $post_customer_data['billing_postcode'] = $customer_data['postcode']; 393 } 394 WC()->customer = $customer; 395 396 } 397 WC()->session->set('refresh_totals', true); 398 $cart->calculate_totals(); 399 WC()->cart = $cart; 400 401 $post_data = implode('&',$post_customer_data); 402 $_POST['billing_email'] = $customer_data['email']; 403 $_POST['post_data'] = $post_data; 404 $_GET['wc-ajax'] = 'update_order_review'; 405 406 407 $cart->calculate_totals(); 408 409 $discount_amount = 0; 410 $coupons = WC()->cart->get_coupons(); 411 $discount_type = 'fixed'; 412 foreach($coupons as $coupon) 413 { 414 $discount_amount += $coupon->get_amount(); 415 $tmp_discount_type = $coupon->get_discount_type(); 416 if($tmp_discount_type == 'percent') 417 { 418 $discount_type = 'percent'; 419 } 420 } 421 if($discount_amount) 422 { 423 $result = array( 424 'discount_amount' => $discount_amount, 425 'discount_type' => $discount_type // percent , fixed 426 427 ); 428 } 429 430 wp_set_current_user(0); 431 if(!$is_api) 432 { 433 $cart = new WC_Cart(); 434 if(!empty($customer_data)) { 435 436 if ($customer_data['id'] && $customer_data['id'] > 0) { 437 wp_set_current_user($customer_data['id']); 438 } 439 440 } 441 $items = $cart_data['items']; 442 foreach($items as $item) 443 { 444 $product_id = isset($item['product_id']) ? $item['product_id'] : 0; 445 $product_qty = isset($item['qty']) ? $item['qty'] : 0; 446 if($product_id && $product_qty) 447 { 448 $cart->add_to_cart($product_id,$product_qty); 449 } 450 } 451 452 $post_customer_data = array(); 453 if(!empty($customer_data)) 454 { 455 $customer = $cart->get_customer(); 456 457 458 if(isset($customer_data['email']) && $customer_data['email']) 459 { 460 $customer->set_email($customer_data['email']); 461 $post_customer_data['billing_email'] = $customer_data['email']; 462 } 463 if(isset($customer_data['firstname']) && $customer_data['firstname']) 464 { 465 $customer->set_first_name($customer_data['firstname']); 466 $post_customer_data['billing_first_name'] = $customer_data['firstname']; 467 } 468 if(isset($customer_data['lastname']) && $customer_data['lastname']) 469 { 470 $customer->set_last_name($customer_data['lastname']); 471 $post_customer_data['billing_last_name'] = $customer_data['lastname']; 472 } 473 if($customer_data['address']) 474 { 475 $customer->set_address($customer_data['address']); 476 $post_customer_data['billing_address_1'] = $customer_data['address']; 477 } 478 479 if(isset($customer_data['address_2']) && $customer_data['address_2']) 480 { 481 $customer->set_address_2($customer_data['address_2']); 482 $post_customer_data['billing_address_2'] = $customer_data['address_2']; 483 } 484 485 if(isset($customer_data['state']) && $customer_data['state']) 486 { 487 $customer->set_state($customer_data['state']); 488 $post_customer_data['billing_state'] = $customer_data['state']; 489 } 490 491 if(isset($customer_data['city']) && $customer_data['city']) 492 { 493 $customer->set_city($customer_data['city']); 494 $post_customer_data['billing_city'] = $customer_data['city']; 495 } 496 497 if(isset($customer_data['country']) && $customer_data['country']) 498 { 499 $customer->set_country($customer_data['country']); 500 $post_customer_data['billing_country'] = $customer_data['country']; 501 } 502 503 if(isset($customer_data['postcode']) && $customer_data['postcode']) 504 { 505 $customer->set_postcode($customer_data['postcode']); 506 $post_customer_data['billing_postcode'] = $customer_data['postcode']; 507 } 508 WC()->customer = $customer; 509 510 } 511 WC()->session->set('refresh_totals', true); 512 $cart->calculate_totals(); 513 WC()->cart = $cart; 514 515 $post_data = implode('&',$post_customer_data); 516 $_POST['billing_email'] = $customer_data['email']; 517 $_POST['post_data'] = $post_data; 518 $_GET['wc-ajax'] = 'update_order_review'; 519 520 521 $cart->calculate_totals(); 522 523 $discount_amount = 0; 524 $coupons = WC()->cart->get_coupons(); 525 $discount_type = 'fixed'; 526 foreach($coupons as $coupon) 527 { 528 $discount_amount += $coupon->get_amount(); 529 $tmp_discount_type = $coupon->get_discount_type(); 530 if($tmp_discount_type == 'percent') 531 { 532 $discount_type = 'percent'; 533 } 534 } 535 if($discount_amount) 536 { 537 $result = array( 538 'discount_amount' => $discount_amount, 539 'discount_type' => $discount_type // percent , fixed 540 541 ); 542 } 543 544 wp_set_current_user(0); 545 }else{ 546 // api calc discount 547 } 548 431 549 return $result; 432 550 } -
wpos-lite-version/trunk/readme.txt
r3373861 r3435849 39 39 40 40 🎥 Watch the demo video: 41 https:// www.youtube.com/watch?v=dQw4w9WgXcQ41 https://youtu.be/zqCd4Ox3NIk?si=CUv6q0m76N4inOMM 42 42 43 43 ---
Note: See TracChangeset
for help on using the changeset viewer.