Changeset 3257191
- Timestamp:
- 03/17/2025 02:21:05 PM (13 months ago)
- Location:
- simpler-checkout
- Files:
-
- 24 edited
- 1 copied
-
tags/1.1.2 (copied) (copied from simpler-checkout/trunk)
-
tags/1.1.2/README.txt (modified) (2 diffs)
-
tags/1.1.2/includes/Models/CartItem.php (modified) (3 diffs)
-
tags/1.1.2/includes/Services/CartHelper.php (modified) (2 diffs)
-
tags/1.1.2/includes/Services/QuotationService.php (modified) (3 diffs)
-
tags/1.1.2/includes/button.php (modified) (6 diffs)
-
tags/1.1.2/includes/compat.php (modified) (1 diff)
-
tags/1.1.2/includes/constants.php (modified) (1 diff)
-
tags/1.1.2/simpler.php (modified) (1 diff)
-
tags/1.1.2/vendor/autoload.php (modified) (1 diff)
-
tags/1.1.2/vendor/composer/autoload_real.php (modified) (3 diffs)
-
tags/1.1.2/vendor/composer/autoload_static.php (modified) (2 diffs)
-
tags/1.1.2/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/includes/Models/CartItem.php (modified) (3 diffs)
-
trunk/includes/Services/CartHelper.php (modified) (2 diffs)
-
trunk/includes/Services/QuotationService.php (modified) (3 diffs)
-
trunk/includes/button.php (modified) (6 diffs)
-
trunk/includes/compat.php (modified) (1 diff)
-
trunk/includes/constants.php (modified) (1 diff)
-
trunk/simpler.php (modified) (1 diff)
-
trunk/vendor/autoload.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_real.php (modified) (3 diffs)
-
trunk/vendor/composer/autoload_static.php (modified) (2 diffs)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simpler-checkout/tags/1.1.2/README.txt
r3244572 r3257191 5 5 Tested up to: 6.5 6 6 Requires PHP: 7.0 7 Stable tag: 1.1. 17 Stable tag: 1.1.2 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 35 35 36 36 == Changelog == 37 38 == 1.1.2 39 Compat: [WPC Product Bundles for WooCommerce] (https://wordpress.org/plugins/woo-product-bundle/) 40 Compat: [WPC Frequently Bought Together for WooCommerce] (https://wordpress.org/plugins/woo-bought-together/) 37 41 38 42 == 1.1.1 -
simpler-checkout/tags/1.1.2/includes/Models/CartItem.php
r2776966 r3257191 22 22 */ 23 23 private $bundle_configuration; 24 /** 25 * @var array 26 */ 27 private $bundled; 28 /** 29 * @var string 30 */ 31 private $bundle_type; 24 32 25 public function __construct($product_id, $quantity, $attrs = [], $bundle d = [])33 public function __construct($product_id, $quantity, $attrs = [], $bundle_configuration = [], $bundled = [], $bundle_type = null) 26 34 { 27 35 $this->product_id = $product_id; 28 36 $this->quantity = $quantity; 29 37 $this->attrs = $attrs; 30 $this->bundle_configuration = $bundled; 38 $this->bundle_configuration = $bundle_configuration; 39 $this->bundled = $bundled; 40 $this->bundle_type = $bundle_type; 31 41 } 32 42 … … 36 46 return new ProductAttribute($el['key'], $el['value']); 37 47 }, $json['attributes'] ?? []); 38 return new CartItem($json['product_id'], $json['quantity'], $attrs, $json['bundle d'] ?? []);48 return new CartItem($json['product_id'], $json['quantity'], $attrs, $json['bundle_configuration'] ?? [], $json['bundled'] ?? [], $json['bundle_type'] ?? null); 39 49 } 40 50 … … 81 91 return $config; 82 92 } 93 94 public function get_bundled() 95 { 96 if(!empty($this->bundled)){ 97 foreach ($this->bundled as &$product) { 98 if (!array_key_exists('attributes', $product)) { 99 $product['attributes'] = []; 100 } else { 101 $product['attributes'] = array_reduce($product['attributes'], function ($acc, $el) { 102 $acc[$el['key']] = $el['value']; 103 return $acc; 104 }, []); 105 } 106 } 107 } 108 return $this->bundled; 109 } 110 111 public function has_bundled() 112 { 113 return !empty($this->bundled); 114 } 115 116 public function get_bundle_type() 117 { 118 return $this->bundle_type; 119 } 120 121 public function set_bundle_type($bundle_type) 122 { 123 $this->bundle_type = $bundle_type; 124 } 83 125 } -
simpler-checkout/tags/1.1.2/includes/Services/CartHelper.php
r3111836 r3257191 25 25 private function add_item_to_cart(CartItem $item) 26 26 { 27 $product = \wc_get_product($item->get_product_id());28 27 $productAdded = false; 29 if (is_a($product, 'WC_Product_Bundle')) { 30 $productAdded = $this->add_bundle_to_cart($product, $item); 28 if(!$item->get_bundle_type() && $item->has_bundled()){ 29 30 $bundle_type = apply_filters('simplerwc_get_bundle_type_of_the_product', null,\wc_get_product( $item->get_product_id())); 31 32 $item->set_bundle_type($bundle_type); 33 } 34 if ($item->get_bundle_type()) { 35 $productAdded = apply_filters('simplerwc_add_simpler_bundle_to_cart', false, $item); 31 36 } else { 32 37 $productAdded = \WC()->cart->add_to_cart( … … 37 42 apply_filters('simplerwc_get_cart_item_data', [], $item) 38 43 ); 39 40 // Woo Product Bundles configured through Linked Products41 foreach ($item->get_bundle_configuration() as $bundled) {42 \WC()->cart->add_to_cart(43 $bundled['product_id'],44 $bundled['quantity'],45 NULL,46 $bundled['attributes'],47 apply_filters('simplerwc_get_cart_item_data', ['bundle_sell_of' => $productAdded], $bundled)48 );49 }50 if (class_exists('\WC_PB_BS_Cart') && method_exists('\WC_PB_BS_Cart', 'load_bundle_sells_into_session')) {51 \WC_PB_BS_Cart::load_bundle_sells_into_session(\WC()->cart);52 }53 44 } 54 55 45 if (is_bool($productAdded) && !$productAdded) { 56 46 throw $this->addProductToCartException 57 47 ?: new InvalidProductException(json_encode(WC()->session->get('wc_notices'))); 58 48 } 59 60 49 do_action('simplerwc_after_add_to_cart', $productAdded, $item); 61 50 } 51 } 62 52 63 private function add_bundle_to_cart($bundle, $item)64 {65 // the final bundle configuration to be added to cart66 $configuration = [];67 53 68 // get bundle configurations69 $bundled = \WC_PB_DB::query_bundled_items(array(70 'return' => 'id=>product_id',71 'bundle_id' => array($bundle->get_id())72 ));73 74 // try to match the requested configuration with one of the registered bundles75 foreach ($item->get_bundle_configuration() as $bundle_config) {76 $found = false;77 foreach ($bundled as $bundle_id => $product_id) {78 if ($bundle_config['product_id'] == $product_id) {79 $configuration[$bundle_id] = $bundle_config;80 $configuration[$bundle_id]['optional_selected'] = 'yes';81 $found = true;82 break;83 }84 }85 86 // if not found, check if variation87 if (!$found) {88 $product = \wc_get_product($bundle_config['product_id']);89 if ($product->is_type('variation')) {90 // if it's a variation try searching again with parent's id91 /** @var \WC_Product_Variable $product */92 foreach ($bundled as $bundle_id => $product_id) {93 if ($product->get_parent_id() == $product_id) {94 $configuration[$bundle_id] = $this->construct_variation_configuration($bundle_config, $product);95 break;96 }97 }98 }99 }100 }101 102 // fill configuration keys for not-selected bundled items103 foreach ($bundled as $bundle_id => $product_id) {104 if (!array_key_exists($bundle_id, $configuration)) {105 $configuration[$bundle_id] = [106 'optional_selected' => 'no'107 ];108 }109 }110 111 return \WC_PB()->cart->add_bundle_to_cart(112 $item->get_product_id(),113 $item->get_quantity(),114 $configuration115 );116 }117 118 private function construct_variation_configuration($bundle, $product)119 {120 $c = $bundle;121 foreach ($product->get_variation_attributes() as $k => $v) {122 if (!array_key_exists($k, $bundle['attributes'])) {123 $c['attributes'][$k] = $v;124 }125 }126 $c['product_id'] = $product->get_parent_id();127 $c['variation_id'] = $bundle['product_id'];128 $c['optional_selected'] = 'yes';129 return $c;130 }131 } -
simpler-checkout/tags/1.1.2/includes/Services/QuotationService.php
r3108447 r3257191 61 61 $this->add_item_to_cart($item); 62 62 } 63 64 63 // apply coupon first to account for coupons that offer free shipping 65 64 $discount = $this->maybe_apply_coupon(); … … 191 190 $products = []; 192 191 foreach (WC()->cart->get_cart() as $lineItem) { 192 193 $lineItem = apply_filters('simplerwc_before_create_quoted_product', $lineItem); 194 193 195 $attributes = []; 194 196 if (!empty($pairs = $lineItem['variation'])) { … … 197 199 } 198 200 } 199 201 200 202 $products[] = new QuotedProduct( 201 203 $lineItem['variation_id'] ?: $lineItem['product_id'], -
simpler-checkout/tags/1.1.2/includes/button.php
r3238494 r3257191 218 218 function simplerwc_prepare_product($product) 219 219 { 220 return [ 221 'items' => [simplerwc_get_product_attributes($product)] 222 ]; 220 if ($bundle_type = apply_filters('simplerwc_product_is_bundle_container', false, $product)) { 221 return ['items' => [simplerwc_get_product_attributes($product,$bundle_type)] ]; 222 }else{ 223 return ['items' => [simplerwc_get_product_attributes($product)] ]; 224 } 223 225 } 224 226 … … 229 231 'items' => [] 230 232 ]; 231 232 233 if (is_array($coupons) && count($coupons) > 0 && is_string($coupons[0]) && strlen($coupons[0]) > 0) { 233 234 $ret['coupon'] = $coupons[0]; 234 235 } 235 236 236 foreach ($cart->get_cart_contents() as $cart_item) { 237 237 if (!array_key_exists('data', $cart_item) || !($cart_item['data'] instanceof WC_Product)) { 238 238 continue; 239 239 } 240 241 240 if (apply_filters('simplerwc_button_should_ignore_cart_item', false, $cart_item)) { 242 241 continue; 243 242 } 244 245 243 // we'll bundle this in its container 246 if ( simplerwc_cart_item_is_bundled($cart_item)) {244 if (apply_filters('simplerwc_cart_item_is_bundled', false, $cart_item)) { 247 245 continue; 248 246 } 249 250 if (function_exists('wc_pb_is_bundle_container_cart_item') && \wc_pb_is_bundle_container_cart_item($cart_item)) { 251 $bundled_items = \wc_pb_get_bundled_cart_items($cart_item); 252 foreach ($bundled_items as $idx => $item) { 253 $bundled_items[$idx]['quantity'] = $item['quantity'] / $cart_item['quantity']; 254 } 255 array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items)); 256 } else { 257 $bundled_items = []; 258 $cross_sell_items = $cart_item["bundle_sells"] ?? []; 259 foreach ($cross_sell_items as $id) { 260 $bundled_items[] = $cart->get_cart_item($id); 261 } 262 array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items)); 247 if ($bundle_type = apply_filters('simplerwc_cart_item_is_bundle_container', false, $cart_item)) { 248 $bundled_items = apply_filters('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', [], $cart, $cart_item, $bundle_type); 249 array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items, $bundle_type)); 250 }else{ 251 array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item)); 263 252 } 264 253 } … … 266 255 } 267 256 268 function simplerwc_get_cart_item_attributes($cart_item, $bundled = null) 269 { 270 $attrs = simplerwc_get_product_attributes($cart_item['data']); 271 257 function simplerwc_get_cart_item_attributes($cart_item, $bundled_cart_items = null, $bundle_type = null) 258 { 259 $attrs = simplerwc_get_product_attributes($cart_item['data'], $bundle_type); 272 260 if (isset($cart_item['quantity'])) { 273 261 $attrs['quantity'] = $cart_item['quantity']; 274 262 } 275 276 263 if (is_a($cart_item['data'], 'WC_Product_Variation')) { 277 264 /*** @var \WC_Product_Variation $product */ 278 265 $attrs['attributes'] = array_key_exists('variation', $cart_item) ? $cart_item['variation'] : $product->get_variation_attributes(); 279 266 } 280 281 if (isset($bundled) && count($bundled) > 0) { 267 if (isset($bundled_cart_items) && count($bundled_cart_items) > 0) { 282 268 $attrs['bundled'] = array_values(array_map(function ($el) { 283 269 return simplerwc_get_cart_item_attributes($el); 284 }, $bundled)); 285 } 286 270 }, $bundled_cart_items)); 271 } 287 272 return $attrs; 288 273 } … … 291 276 * @param \WC_Product $product The product to extract information from 292 277 */ 293 function simplerwc_get_product_attributes($product )278 function simplerwc_get_product_attributes($product,$bundle_type = null) 294 279 { 295 280 $attrs = [ … … 311 296 /** @var \WC_Product_Variation $product */ 312 297 $attrs['attributes'] = apply_filters('simplerwc_button_get_product_attributes', $product->get_variation_attributes(), $product); 313 } else if (is_a($product, 'WC_Product_Bundle')) { 314 /** @var \WC_Product_Bundle $product */ 315 $bundled = \WC_PB_DB::query_bundled_items([ 316 'return' => 'id=>product_id', 317 'bundle_id' => [$product->get_id()] 318 ]); 319 $attrs['bundle_configuration'] = array_reduce($bundled, function ($acc, $el) { 320 $product = \wc_get_product($el); 321 if (!$product || \is_wp_error($product)) { 322 return $acc; 323 } 324 $acc[strval($el)] = simplerwc_get_product_attributes($product); 325 return $acc; 326 }, []); 327 } 328 298 } 299 if($bundle_type){ 300 $attrs['bundle_type'] = $bundle_type; 301 $attrs['product_type'] = apply_filters('simplerwc_get_product_type_of_the_bundle',$product->get_type(), $bundle_type); 302 $attrs['bundle_configuration'] = []; 303 $bundled_products = apply_filters('simplerwc_get_all_products_linked_to_the_bundle_product',[], $product, $bundle_type); 304 foreach($bundled_products as $bundled_product){ 305 $attrs['bundle_configuration'][strval($bundled_product->get_id())] = simplerwc_get_product_attributes($bundled_product); 306 } 307 } 329 308 return $attrs; 330 309 } … … 339 318 return in_array('administrator', wp_get_current_user()->roles, true); 340 319 } 341 342 320 if (!is_array($excludedRoles = get_option('simplerwc_excluded_user_roles', [])) || !is_array($roles = wp_get_current_user()->roles)) { 343 321 return true; 344 322 } 345 346 323 return count(array_intersect($excludedRoles, $roles)) === 0; 347 324 } 348 349 function simplerwc_cart_item_is_bundled($item)350 {351 // check if is bundle product352 if (function_exists('wc_pb_is_bundled_cart_item') && \wc_pb_is_bundled_cart_item($item)) {353 return true;354 }355 356 if (array_key_exists('bundle_sell_of', $item)) {357 return true;358 }359 360 return false;361 } -
simpler-checkout/tags/1.1.2/includes/compat.php
r3244572 r3257191 213 213 } 214 214 add_action('simplerwc_product_controller_request_before', 'simplerwc_rp_wcdpd_set_is_product_feed', 1, 0); 215 216 217 218 219 // BUNDLES 220 221 // WC_PB 222 function simplerwc_compat_wc_pb_cart_item_is_bundled($value, $cart_item) 223 { 224 if (function_exists('wc_pb_is_bundled_cart_item') && \wc_pb_is_bundled_cart_item($cart_item)) { 225 return true; 226 } 227 return $value; 228 } 229 add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_wc_pb_cart_item_is_bundled', 10, 2); 230 231 function simplerwc_compat_wc_pb_cart_item_is_bundle_container($value, $cart_item) 232 { 233 if (function_exists('wc_pb_is_bundle_container_cart_item') && \wc_pb_is_bundle_container_cart_item($cart_item)) { 234 return 'wc_pb'; 235 } 236 return $value; 237 } 238 add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_wc_pb_cart_item_is_bundle_container', 10, 2); 239 240 function simplerwc_compat_wc_pb_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type) 241 { 242 if($bundle_type!='wc_pb') return $value; 243 244 if (function_exists('wc_pb_get_bundled_cart_items') ){ 245 $bundled_items = \wc_pb_get_bundled_cart_items($cart_item); 246 foreach ($bundled_items as $idx => $item) { 247 $bundled_items[$idx]['quantity'] = $item['quantity'] / $cart_item['quantity']; 248 } 249 return $bundled_items; 250 } 251 252 return $value; 253 } 254 add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_wc_pb_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4); 255 256 function simplerwc_compat_wc_pb_product_is_bundle_container($value, $product) 257 { 258 if (is_a($product, 'WC_Product_Bundle')) { 259 return 'wc_pb'; 260 } 261 return $value; 262 } 263 add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_wc_pb_product_is_bundle_container', 10, 2); 264 265 function simplerwc_compat_wc_pb_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type) 266 { 267 if($bundle_type!='wc_pb') return $value; 268 269 if (is_a($product, 'WC_Product_Bundle') && class_exists('WC_PB_DB')) { 270 $bundled_products = \WC_PB_DB::query_bundled_items([ 271 'return' => 'id=>product_id', 272 'bundle_id' => [$product->get_id()] 273 ]); 274 $value = array_reduce($bundled_products, function ($acc, $el) { 275 $product = \wc_get_product($el); 276 if (!$product || \is_wp_error($product)) { 277 return $acc; 278 } 279 $acc[] = $product; 280 return $acc; 281 }, []); 282 } 283 return $value; 284 } 285 add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_wc_pb_get_all_products_linked_to_the_bundle_product', 10, 3); 286 287 function simplerwc_compat_wc_pb_add_simpler_bundle_to_cart($value, $simpler_item) 288 { 289 if($simpler_item->get_bundle_type()!='wc_pb') return $value; 290 291 if (!class_exists('WC_PB_DB')) return $value; 292 293 // the final bundle configuration to be added to cart 294 $configuration = []; 295 296 // get bundle configurations 297 $bundled = \WC_PB_DB::query_bundled_items(array( 298 'return' => 'id=>product_id', 299 'bundle_id' => array($simpler_item->get_product_id()) 300 )); 301 302 // try to match the requested configuration with one of the registered bundles 303 foreach ($simpler_item->get_bundled() as $bundle_config) { 304 $found = false; 305 foreach ($bundled as $bundle_id => $product_id) { 306 if ($bundle_config['product_id'] == $product_id) { 307 $configuration[$bundle_id] = $bundle_config; 308 $configuration[$bundle_id]['optional_selected'] = 'yes'; 309 $found = true; 310 break; 311 } 312 } 313 314 // if not found, check if variation 315 if (!$found) { 316 $product = \wc_get_product($bundle_config['product_id']); 317 if ($product->is_type('variation')) { 318 // if it's a variation try searching again with parent's id 319 /** @var \WC_Product_Variable $product */ 320 foreach ($bundled as $bundle_id => $product_id) { 321 if ($product->get_parent_id() == $product_id) { 322 $configuration[$bundle_id] = simplerwc_compat_wc_pb_construct_variation_configuration($bundle_config, $product); 323 break; 324 } 325 } 326 } 327 } 328 } 329 330 // fill configuration keys for not-selected bundled items 331 foreach ($bundled as $bundle_id => $product_id) { 332 if (!array_key_exists($bundle_id, $configuration)) { 333 $configuration[$bundle_id] = [ 334 'optional_selected' => 'no' 335 ]; 336 } 337 } 338 339 return \WC_PB()->cart->add_bundle_to_cart( 340 $simpler_item->get_product_id(), 341 $simpler_item->get_quantity(), 342 $configuration 343 ); 344 } 345 function simplerwc_compat_wc_pb_construct_variation_configuration($bundle, $product) 346 { 347 $c = $bundle; 348 foreach ($product->get_variation_attributes() as $k => $v) { 349 if (!array_key_exists($k, $bundle['attributes'])) { 350 $c['attributes'][$k] = $v; 351 } 352 } 353 $c['product_id'] = $product->get_parent_id(); 354 $c['variation_id'] = $bundle['product_id']; 355 $c['optional_selected'] = 'yes'; 356 return $c; 357 } 358 add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_wc_pb_add_simpler_bundle_to_cart', 10, 2); 359 360 function simplerwc_compat_wc_pb_get_product_type_of_the_bundle($value,$bundle_type) 361 { 362 if($bundle_type=='wc_pb') return 'bundle'; 363 return $value; 364 } 365 add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_wc_pb_get_product_type_of_the_bundle', 10, 2); 366 367 function simplerwc_compat_wc_pb_get_bundle_type_of_the_product($value,$product) 368 { 369 if($value) return $value; 370 if (is_a($product, 'WC_Product_Bundle') && class_exists('WC_PB_DB')) { 371 return 'wc_pb'; 372 } 373 return $value; 374 } 375 add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_wc_pb_get_bundle_type_of_the_product', 10, 2); 376 377 378 379 // WPC Smart Bundles 380 function simplerwc_compat_woosb_cart_item_is_bundled($value, $cart_item) 381 { 382 if (array_key_exists('woosb_parent_id',$cart_item)) { 383 return true; 384 } 385 return $value; 386 } 387 add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woosb_cart_item_is_bundled', 10, 2); 388 389 function simplerwc_compat_woosb_cart_item_is_bundle_container($value, $cart_item) 390 { 391 if (isset($cart_item['woosb_ids']) && !empty($cart_item['woosb_ids'])){ 392 return 'woosb'; 393 } 394 return $value; 395 } 396 add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woosb_cart_item_is_bundle_container', 10, 2); 397 398 function simplerwc_compat_woosb_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type) 399 { 400 if($bundle_type!='woosb') return $value; 401 402 $bundled_items = []; 403 $bundle_ids = explode(',', $cart_item['woosb_ids']); 404 405 foreach ($bundle_ids as $id) { 406 foreach ($cart->get_cart_contents() as $item) { 407 if ($item['product_id'] == $id) { 408 $bundled_items[] = $item; 409 break; 410 } 411 } 412 } 413 return $bundled_items; 414 } 415 add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woosb_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4); 416 417 function simplerwc_compat_woosb_product_is_bundle_container($value, $product) 418 { 419 if (is_a( $product, 'WC_Product_Woosb' )) { 420 return 'woosb'; 421 } 422 return $value; 423 } 424 add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woosb_product_is_bundle_container', 10, 2); 425 426 function simplerwc_compat_woosb_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type) 427 { 428 if($bundle_type!='woosb') return $value; 429 430 if (is_a( $product, 'WC_Product_Woosb' )) { 431 $bundle_items = $product->get_meta('woosb_ids'); 432 if (is_array($bundle_items)) { 433 foreach ($bundle_items as $key => $item) { 434 $id = isset($item['id']) ? intval($item['id']) : 0; 435 if ($id > 0) { 436 $bundled_product = \wc_get_product($id); 437 if ($bundled_product) { 438 $value[] = $bundled_product; 439 } 440 } 441 } 442 } 443 } 444 return $value; 445 } 446 add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woosb_get_all_products_linked_to_the_bundle_product', 10, 3); 447 448 function simplerwc_compat_woosb_add_simpler_bundle_to_cart($value, $simpler_item) 449 { 450 if($simpler_item->get_bundle_type()!='woosb') return $value; 451 452 if (!class_exists('WPCleverWoosb')) return $value; 453 454 $WPCleverWoosb = new \WPCleverWoosb; 455 $cart_data = apply_filters('simplerwc_get_cart_item_data', [], $simpler_item); 456 457 $product_id = $simpler_item->get_product_id(); 458 $quantity = $simpler_item->get_quantity(); 459 $variation_id = NULL; 460 $variation = $simpler_item->get_attributes_array(); 461 462 $cart_item_data = $WPCleverWoosb->add_cart_item_data($cart_data,$product_id); 463 if(isset($cart_item_data['woosb_ids'])){ 464 $new_woosb_ids = []; 465 $woosb_ids = explode(',',$cart_item_data['woosb_ids']); 466 foreach($woosb_ids as $woosb_id){ 467 list($pid,$pkey,$pqty) = explode('/',$woosb_id); 468 foreach($simpler_item->get_bundled() as $b_item){ 469 if($pid == $b_item['product_id']){ 470 $pqty = $b_item['quantity']; 471 $new_woosb_id = implode('/',[$pid,$pkey,$pqty]); 472 $new_woosb_ids[]=$new_woosb_id; 473 } 474 } 475 } 476 $cart_item_data['woosb_ids'] = implode(',',$new_woosb_ids); 477 } 478 479 $cart_item_key = WC()->cart->add_to_cart( 480 $product_id, 481 $quantity, 482 $variation_id, 483 $variation, 484 $cart_item_data 485 ); 486 487 $WPCleverWoosb->add_to_cart($cart_item_key, $product_id, $quantity,null,[],$cart_item_data); 488 return $cart_item_key; 489 } 490 add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woosb_add_simpler_bundle_to_cart', 10, 2); 491 492 function simplerwc_compat_woosb_before_create_quoted_product($lineItem) 493 { 494 if(isset($lineItem['woosb_price'])){ 495 $lineItem['line_total'] = $lineItem['woosb_price']; 496 $lineItem['line_subtotal'] = $lineItem['woosb_price']; 497 } 498 if(isset($lineItem['woosb_parent_id'])){ 499 $lineItem['line_total'] = 0; 500 $lineItem['line_subtotal'] = 0; 501 } 502 return $lineItem; 503 } 504 add_filter('simplerwc_before_create_quoted_product', 'simplerwc_compat_woosb_before_create_quoted_product', 10, 1); 505 506 function simplerwc_compat_woosb_get_product_type_of_the_bundle($value,$bundle_type) 507 { 508 if($bundle_type=='woosb') return 'bundle'; 509 return $value; 510 } 511 add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woosb_get_product_type_of_the_bundle', 10, 2); 512 513 function simplerwc_compat_woosb_get_bundle_type_of_the_product($value,$product) 514 { 515 if($value) return $value; 516 if (is_a( $product, 'WC_Product_Woosb' )) { 517 return 'woosb'; 518 } 519 return $value; 520 } 521 add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woosb_get_bundle_type_of_the_product', 10, 2); 522 523 524 525 // WPC Frequently Brought Together 526 function simplerwc_compat_woobt_cart_item_is_bundled($value, $cart_item) 527 { 528 if (array_key_exists('woobt_parent_id',$cart_item)) { 529 return true; 530 } 531 return $value; 532 } 533 add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woobt_cart_item_is_bundled', 10, 2); 534 535 function simplerwc_compat_woobt_cart_item_is_bundle_container($value, $cart_item) 536 { 537 if (isset($cart_item['woobt_ids']) && !empty($cart_item['woobt_ids'])){ 538 return 'woobt'; 539 } 540 return $value; 541 } 542 add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woobt_cart_item_is_bundle_container', 10, 2); 543 544 function simplerwc_compat_woobt_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type) 545 { 546 if($bundle_type!='woobt') return $value; 547 548 $bundled_items = []; 549 $bundle_ids = explode(',', $cart_item['woobt_ids']); 550 551 foreach ($bundle_ids as $bundle_line) { 552 list($id,$code,$qty) = explode('/',$bundle_line); 553 foreach ($cart->get_cart_contents() as $item) { 554 if ($item['product_id'] == $id && isset($item['woobt_parent_id']) && $item['woobt_parent_id']==$cart_item['product_id']) { 555 $bundled_items[] = $item; 556 break; 557 } 558 } 559 } 560 return $bundled_items; 561 } 562 add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woobt_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4); 563 564 function simplerwc_compat_woobt_product_is_bundle_container($value, $product) 565 { 566 $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true); 567 568 if (empty($linked_products)) return $value; 569 570 return 'woobt'; 571 } 572 add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woobt_product_is_bundle_container', 10, 2); 573 574 function simplerwc_compat_woobt_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type) 575 { 576 if($bundle_type!='woobt') return $value; 577 578 $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true); 579 580 if (empty($linked_products)) return $value; 581 582 $linked_products = maybe_unserialize($linked_products); 583 584 foreach ($linked_products as $key => $item) { 585 if (isset($item['id'])) { 586 $product = wc_get_product($item['id']); 587 if ($product) { 588 $value[]=$product; 589 } 590 } 591 } 592 return $value; 593 } 594 add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woobt_get_all_products_linked_to_the_bundle_product', 10, 3); 595 596 function simplerwc_compat_woobt_add_simpler_bundle_to_cart($value, $simpler_item) 597 { 598 if($simpler_item->get_bundle_type()!='woobt') return $value; 599 600 $main_product_metadata = apply_filters('simplerwc_get_cart_item_data', [], $simpler_item); 601 602 $main_product_id = $simpler_item->get_product_id(); 603 $main_product_cart_key = WC()->cart->add_to_cart( 604 $main_product_id, 605 $simpler_item->get_quantity(), 606 null, 607 $simpler_item->get_attributes_array(), 608 $main_product_metadata 609 ); 610 $value = $main_product_cart_key; 611 612 if (class_exists('WPCleverWoobt')) { 613 $WPCleverWoobt = new \WPCleverWoobt; 614 615 $main_product_metadata['woobt_ids'] = ''; 616 $ids = []; 617 $linked_products = $WPCleverWoobt->get_product_items( $main_product_id ); 618 foreach ($linked_products as $linked_key => $linked_product){ 619 foreach($simpler_item->get_bundled() as $simpler_bundled_item){ 620 if($simpler_bundled_item['product_id'] == $linked_product['id']){ 621 $ids[] = $simpler_bundled_item['product_id'].'/'.$linked_key.'/'.$simpler_bundled_item['quantity']; 622 } 623 } 624 } 625 $main_product_metadata['woobt_ids']=implode(',',$ids); 626 $WPCleverWoobt->add_to_cart( 627 $main_product_cart_key, 628 $main_product_id, 629 $simpler_item->get_quantity(), 630 null, 631 $simpler_item->get_attributes_array(), 632 $main_product_metadata 633 ); 634 $value = $main_product_cart_key; 635 } 636 WC()->cart->calculate_totals(); 637 return $value; 638 } 639 add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woobt_add_simpler_bundle_to_cart', 10, 2); 640 641 function simplerwc_compat_woobt_get_product_type_of_the_bundle($value,$bundle_type) 642 { 643 return $value; 644 } 645 add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woobt_get_product_type_of_the_bundle', 10, 2); 646 647 function simplerwc_compat_woobt_get_bundle_type_of_the_product($value,$product) 648 { 649 if($value) return $value; 650 $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true); 651 if (!empty($linked_products)) return 'woobt'; 652 return $value; 653 } 654 add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woobt_get_bundle_type_of_the_product', 10, 2); 655 656 657 658 // WC Linked products 659 function simplerwc_compat_woocommerce_cart_item_is_bundled($value, $cart_item) 660 { 661 if (array_key_exists('bundle_sell_of',$cart_item)) { 662 return true; 663 } 664 return $value; 665 } 666 add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woocommerce_cart_item_is_bundled', 10, 2); 667 668 function simplerwc_compat_woocommerce_cart_item_is_bundle_container($value, $cart_item) 669 { 670 if (isset($cart_item['bundle_sells']) && !empty($cart_item['bundle_sells'])){ 671 return 'woocommerce'; 672 } 673 return $value; 674 } 675 add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woocommerce_cart_item_is_bundle_container', 10, 2); 676 677 function simplerwc_compat_woocommerce_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type) 678 { 679 if($bundle_type!='woocommerce') return $value; 680 681 $bundled_items = []; 682 $cross_sell_items = $cart_item["bundle_sells"] ?? []; 683 foreach ($cross_sell_items as $id) { 684 $bundled_items[] = $cart->get_cart_item($id); 685 } 686 return $bundled_items; 687 } 688 add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woocommerce_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4); 689 690 function simplerwc_compat_woocommerce_product_is_bundle_container($value, $product) 691 { 692 $linked_products = get_post_meta($product->get_id(), 'bundle_sells', true); 693 694 if (empty($linked_products)) return $value; 695 696 return $value; 697 } 698 add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woocommerce_product_is_bundle_container', 10, 2); 699 700 function simplerwc_compat_woocommerce_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type) 701 { 702 if($bundle_type!='woocommerce') return $value; 703 704 return $value; 705 } 706 add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woocommerce_get_all_products_linked_to_the_bundle_product', 10, 3); 707 708 function simplerwc_compat_woocommerce_add_simpler_bundle_to_cart($value, $simpler_item) 709 { 710 if($simpler_item->get_bundle_type()!='woocommerce') return $value; 711 712 $main_product_cart_key = \WC()->cart->add_to_cart( 713 $simpler_item->get_product_id(), 714 $simpler_item->get_quantity(), 715 NULL, 716 $simpler_item->get_attributes_array(), 717 apply_filters('simplerwc_get_cart_item_data', [], $simpler_item) 718 ); 719 720 // Woo Product Bundles configured through Linked Products 721 foreach ($simpler_item->get_bundled() as $bundled) { 722 \WC()->cart->add_to_cart( 723 $bundled['product_id'], 724 $bundled['quantity'], 725 NULL, 726 $bundled['attributes'], 727 apply_filters('simplerwc_get_cart_item_data', ['bundle_sell_of' => $main_product_cart_key], $bundled) 728 ); 729 } 730 if (class_exists('\WC_PB_BS_Cart') && method_exists('\WC_PB_BS_Cart', 'load_bundle_sells_into_session')) { 731 \WC_PB_BS_Cart::load_bundle_sells_into_session(\WC()->cart); 732 } 733 return $main_product_cart_key; 734 } 735 add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woocommerce_add_simpler_bundle_to_cart', 10, 2); 736 737 function simplerwc_compat_woocommerce_get_product_type_of_the_bundle($value,$bundle_type) 738 { 739 return $value; 740 } 741 add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woocommerce_get_product_type_of_the_bundle', 10, 2); 742 743 function simplerwc_compat_woocommerce_get_bundle_type_of_the_product($value,$product) 744 { 745 if($value) return $value; 746 return 'woocommerce'; 747 } 748 add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woocommerce_get_bundle_type_of_the_product', 11, 2); 749 -
simpler-checkout/tags/1.1.2/includes/constants.php
r3244572 r3257191 1 1 <?php 2 2 3 const SIMPLERWC_VERSION = '1.1. 1';3 const SIMPLERWC_VERSION = '1.1.2'; 4 4 5 5 function simplerwc_get_sdk_uri() -
simpler-checkout/tags/1.1.2/simpler.php
r3244572 r3257191 8 8 * Description: Simpler Checkout lets your customers complete their purchases in seconds, with any payment method they want, in any device or browser and without a password. 9 9 * Tags: woocommerce, checkout, payments, conversion rate 10 * Version: 1.1. 110 * Version: 1.1.2 11 11 * Requires at least: 5.1 12 12 * Tested up to: 6.3.1 -
simpler-checkout/tags/1.1.2/vendor/autoload.php
r3244572 r3257191 5 5 require_once __DIR__ . '/composer/autoload_real.php'; 6 6 7 return ComposerAutoloaderInit0 250069f9335df0d3d59ba9ce9dcfb67::getLoader();7 return ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa::getLoader(); -
simpler-checkout/tags/1.1.2/vendor/composer/autoload_real.php
r3244572 r3257191 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit0 250069f9335df0d3d59ba9ce9dcfb675 class ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa 6 6 { 7 7 private static $loader; … … 25 25 require __DIR__ . '/platform_check.php'; 26 26 27 spl_autoload_register(array('ComposerAutoloaderInit0 250069f9335df0d3d59ba9ce9dcfb67', 'loadClassLoader'), true, true);27 spl_autoload_register(array('ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa', 'loadClassLoader'), true, true); 28 28 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); 29 spl_autoload_unregister(array('ComposerAutoloaderInit0 250069f9335df0d3d59ba9ce9dcfb67', 'loadClassLoader'));29 spl_autoload_unregister(array('ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa', 'loadClassLoader')); 30 30 31 31 $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); … … 33 33 require __DIR__ . '/autoload_static.php'; 34 34 35 call_user_func(\Composer\Autoload\ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb67::getInitializer($loader));35 call_user_func(\Composer\Autoload\ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::getInitializer($loader)); 36 36 } else { 37 37 $map = require __DIR__ . '/autoload_namespaces.php'; -
simpler-checkout/tags/1.1.2/vendor/composer/autoload_static.php
r3244572 r3257191 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb677 class ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( … … 86 86 { 87 87 return \Closure::bind(function () use ($loader) { 88 $loader->prefixLengthsPsr4 = ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb67::$prefixLengthsPsr4;89 $loader->prefixDirsPsr4 = ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb67::$prefixDirsPsr4;90 $loader->classMap = ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb67::$classMap;88 $loader->prefixLengthsPsr4 = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$prefixLengthsPsr4; 89 $loader->prefixDirsPsr4 = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$prefixDirsPsr4; 90 $loader->classMap = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$classMap; 91 91 92 92 }, null, ClassLoader::class); -
simpler-checkout/tags/1.1.2/vendor/composer/installed.php
r3244572 r3257191 1 1 <?php return array( 2 2 'root' => array( 3 'pretty_version' => '1.1. 1',4 'version' => '1.1. 1.0',3 'pretty_version' => '1.1.2', 4 'version' => '1.1.2.0', 5 5 'type' => 'wordpress-plugin', 6 6 'install_path' => __DIR__ . '/../../', 7 7 'aliases' => array(), 8 'reference' => ' bb55c256e100142e4cc55de1af03ca9bcf581777',8 'reference' => '8b7d98f2bf87df11c50d0440d830606ab05ad7ef', 9 9 'name' => 'simpler-checkout/woo', 10 10 'dev' => false, … … 12 12 'versions' => array( 13 13 'simpler-checkout/woo' => array( 14 'pretty_version' => '1.1. 1',15 'version' => '1.1. 1.0',14 'pretty_version' => '1.1.2', 15 'version' => '1.1.2.0', 16 16 'type' => 'wordpress-plugin', 17 17 'install_path' => __DIR__ . '/../../', 18 18 'aliases' => array(), 19 'reference' => ' bb55c256e100142e4cc55de1af03ca9bcf581777',19 'reference' => '8b7d98f2bf87df11c50d0440d830606ab05ad7ef', 20 20 'dev_requirement' => false, 21 21 ), -
simpler-checkout/trunk/README.txt
r3244572 r3257191 5 5 Tested up to: 6.5 6 6 Requires PHP: 7.0 7 Stable tag: 1.1. 17 Stable tag: 1.1.2 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 35 35 36 36 == Changelog == 37 38 == 1.1.2 39 Compat: [WPC Product Bundles for WooCommerce] (https://wordpress.org/plugins/woo-product-bundle/) 40 Compat: [WPC Frequently Bought Together for WooCommerce] (https://wordpress.org/plugins/woo-bought-together/) 37 41 38 42 == 1.1.1 -
simpler-checkout/trunk/includes/Models/CartItem.php
r2776966 r3257191 22 22 */ 23 23 private $bundle_configuration; 24 /** 25 * @var array 26 */ 27 private $bundled; 28 /** 29 * @var string 30 */ 31 private $bundle_type; 24 32 25 public function __construct($product_id, $quantity, $attrs = [], $bundle d = [])33 public function __construct($product_id, $quantity, $attrs = [], $bundle_configuration = [], $bundled = [], $bundle_type = null) 26 34 { 27 35 $this->product_id = $product_id; 28 36 $this->quantity = $quantity; 29 37 $this->attrs = $attrs; 30 $this->bundle_configuration = $bundled; 38 $this->bundle_configuration = $bundle_configuration; 39 $this->bundled = $bundled; 40 $this->bundle_type = $bundle_type; 31 41 } 32 42 … … 36 46 return new ProductAttribute($el['key'], $el['value']); 37 47 }, $json['attributes'] ?? []); 38 return new CartItem($json['product_id'], $json['quantity'], $attrs, $json['bundle d'] ?? []);48 return new CartItem($json['product_id'], $json['quantity'], $attrs, $json['bundle_configuration'] ?? [], $json['bundled'] ?? [], $json['bundle_type'] ?? null); 39 49 } 40 50 … … 81 91 return $config; 82 92 } 93 94 public function get_bundled() 95 { 96 if(!empty($this->bundled)){ 97 foreach ($this->bundled as &$product) { 98 if (!array_key_exists('attributes', $product)) { 99 $product['attributes'] = []; 100 } else { 101 $product['attributes'] = array_reduce($product['attributes'], function ($acc, $el) { 102 $acc[$el['key']] = $el['value']; 103 return $acc; 104 }, []); 105 } 106 } 107 } 108 return $this->bundled; 109 } 110 111 public function has_bundled() 112 { 113 return !empty($this->bundled); 114 } 115 116 public function get_bundle_type() 117 { 118 return $this->bundle_type; 119 } 120 121 public function set_bundle_type($bundle_type) 122 { 123 $this->bundle_type = $bundle_type; 124 } 83 125 } -
simpler-checkout/trunk/includes/Services/CartHelper.php
r3111836 r3257191 25 25 private function add_item_to_cart(CartItem $item) 26 26 { 27 $product = \wc_get_product($item->get_product_id());28 27 $productAdded = false; 29 if (is_a($product, 'WC_Product_Bundle')) { 30 $productAdded = $this->add_bundle_to_cart($product, $item); 28 if(!$item->get_bundle_type() && $item->has_bundled()){ 29 30 $bundle_type = apply_filters('simplerwc_get_bundle_type_of_the_product', null,\wc_get_product( $item->get_product_id())); 31 32 $item->set_bundle_type($bundle_type); 33 } 34 if ($item->get_bundle_type()) { 35 $productAdded = apply_filters('simplerwc_add_simpler_bundle_to_cart', false, $item); 31 36 } else { 32 37 $productAdded = \WC()->cart->add_to_cart( … … 37 42 apply_filters('simplerwc_get_cart_item_data', [], $item) 38 43 ); 39 40 // Woo Product Bundles configured through Linked Products41 foreach ($item->get_bundle_configuration() as $bundled) {42 \WC()->cart->add_to_cart(43 $bundled['product_id'],44 $bundled['quantity'],45 NULL,46 $bundled['attributes'],47 apply_filters('simplerwc_get_cart_item_data', ['bundle_sell_of' => $productAdded], $bundled)48 );49 }50 if (class_exists('\WC_PB_BS_Cart') && method_exists('\WC_PB_BS_Cart', 'load_bundle_sells_into_session')) {51 \WC_PB_BS_Cart::load_bundle_sells_into_session(\WC()->cart);52 }53 44 } 54 55 45 if (is_bool($productAdded) && !$productAdded) { 56 46 throw $this->addProductToCartException 57 47 ?: new InvalidProductException(json_encode(WC()->session->get('wc_notices'))); 58 48 } 59 60 49 do_action('simplerwc_after_add_to_cart', $productAdded, $item); 61 50 } 51 } 62 52 63 private function add_bundle_to_cart($bundle, $item)64 {65 // the final bundle configuration to be added to cart66 $configuration = [];67 53 68 // get bundle configurations69 $bundled = \WC_PB_DB::query_bundled_items(array(70 'return' => 'id=>product_id',71 'bundle_id' => array($bundle->get_id())72 ));73 74 // try to match the requested configuration with one of the registered bundles75 foreach ($item->get_bundle_configuration() as $bundle_config) {76 $found = false;77 foreach ($bundled as $bundle_id => $product_id) {78 if ($bundle_config['product_id'] == $product_id) {79 $configuration[$bundle_id] = $bundle_config;80 $configuration[$bundle_id]['optional_selected'] = 'yes';81 $found = true;82 break;83 }84 }85 86 // if not found, check if variation87 if (!$found) {88 $product = \wc_get_product($bundle_config['product_id']);89 if ($product->is_type('variation')) {90 // if it's a variation try searching again with parent's id91 /** @var \WC_Product_Variable $product */92 foreach ($bundled as $bundle_id => $product_id) {93 if ($product->get_parent_id() == $product_id) {94 $configuration[$bundle_id] = $this->construct_variation_configuration($bundle_config, $product);95 break;96 }97 }98 }99 }100 }101 102 // fill configuration keys for not-selected bundled items103 foreach ($bundled as $bundle_id => $product_id) {104 if (!array_key_exists($bundle_id, $configuration)) {105 $configuration[$bundle_id] = [106 'optional_selected' => 'no'107 ];108 }109 }110 111 return \WC_PB()->cart->add_bundle_to_cart(112 $item->get_product_id(),113 $item->get_quantity(),114 $configuration115 );116 }117 118 private function construct_variation_configuration($bundle, $product)119 {120 $c = $bundle;121 foreach ($product->get_variation_attributes() as $k => $v) {122 if (!array_key_exists($k, $bundle['attributes'])) {123 $c['attributes'][$k] = $v;124 }125 }126 $c['product_id'] = $product->get_parent_id();127 $c['variation_id'] = $bundle['product_id'];128 $c['optional_selected'] = 'yes';129 return $c;130 }131 } -
simpler-checkout/trunk/includes/Services/QuotationService.php
r3108447 r3257191 61 61 $this->add_item_to_cart($item); 62 62 } 63 64 63 // apply coupon first to account for coupons that offer free shipping 65 64 $discount = $this->maybe_apply_coupon(); … … 191 190 $products = []; 192 191 foreach (WC()->cart->get_cart() as $lineItem) { 192 193 $lineItem = apply_filters('simplerwc_before_create_quoted_product', $lineItem); 194 193 195 $attributes = []; 194 196 if (!empty($pairs = $lineItem['variation'])) { … … 197 199 } 198 200 } 199 201 200 202 $products[] = new QuotedProduct( 201 203 $lineItem['variation_id'] ?: $lineItem['product_id'], -
simpler-checkout/trunk/includes/button.php
r3238494 r3257191 218 218 function simplerwc_prepare_product($product) 219 219 { 220 return [ 221 'items' => [simplerwc_get_product_attributes($product)] 222 ]; 220 if ($bundle_type = apply_filters('simplerwc_product_is_bundle_container', false, $product)) { 221 return ['items' => [simplerwc_get_product_attributes($product,$bundle_type)] ]; 222 }else{ 223 return ['items' => [simplerwc_get_product_attributes($product)] ]; 224 } 223 225 } 224 226 … … 229 231 'items' => [] 230 232 ]; 231 232 233 if (is_array($coupons) && count($coupons) > 0 && is_string($coupons[0]) && strlen($coupons[0]) > 0) { 233 234 $ret['coupon'] = $coupons[0]; 234 235 } 235 236 236 foreach ($cart->get_cart_contents() as $cart_item) { 237 237 if (!array_key_exists('data', $cart_item) || !($cart_item['data'] instanceof WC_Product)) { 238 238 continue; 239 239 } 240 241 240 if (apply_filters('simplerwc_button_should_ignore_cart_item', false, $cart_item)) { 242 241 continue; 243 242 } 244 245 243 // we'll bundle this in its container 246 if ( simplerwc_cart_item_is_bundled($cart_item)) {244 if (apply_filters('simplerwc_cart_item_is_bundled', false, $cart_item)) { 247 245 continue; 248 246 } 249 250 if (function_exists('wc_pb_is_bundle_container_cart_item') && \wc_pb_is_bundle_container_cart_item($cart_item)) { 251 $bundled_items = \wc_pb_get_bundled_cart_items($cart_item); 252 foreach ($bundled_items as $idx => $item) { 253 $bundled_items[$idx]['quantity'] = $item['quantity'] / $cart_item['quantity']; 254 } 255 array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items)); 256 } else { 257 $bundled_items = []; 258 $cross_sell_items = $cart_item["bundle_sells"] ?? []; 259 foreach ($cross_sell_items as $id) { 260 $bundled_items[] = $cart->get_cart_item($id); 261 } 262 array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items)); 247 if ($bundle_type = apply_filters('simplerwc_cart_item_is_bundle_container', false, $cart_item)) { 248 $bundled_items = apply_filters('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', [], $cart, $cart_item, $bundle_type); 249 array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item, $bundled_items, $bundle_type)); 250 }else{ 251 array_push($ret['items'], simplerwc_get_cart_item_attributes($cart_item)); 263 252 } 264 253 } … … 266 255 } 267 256 268 function simplerwc_get_cart_item_attributes($cart_item, $bundled = null) 269 { 270 $attrs = simplerwc_get_product_attributes($cart_item['data']); 271 257 function simplerwc_get_cart_item_attributes($cart_item, $bundled_cart_items = null, $bundle_type = null) 258 { 259 $attrs = simplerwc_get_product_attributes($cart_item['data'], $bundle_type); 272 260 if (isset($cart_item['quantity'])) { 273 261 $attrs['quantity'] = $cart_item['quantity']; 274 262 } 275 276 263 if (is_a($cart_item['data'], 'WC_Product_Variation')) { 277 264 /*** @var \WC_Product_Variation $product */ 278 265 $attrs['attributes'] = array_key_exists('variation', $cart_item) ? $cart_item['variation'] : $product->get_variation_attributes(); 279 266 } 280 281 if (isset($bundled) && count($bundled) > 0) { 267 if (isset($bundled_cart_items) && count($bundled_cart_items) > 0) { 282 268 $attrs['bundled'] = array_values(array_map(function ($el) { 283 269 return simplerwc_get_cart_item_attributes($el); 284 }, $bundled)); 285 } 286 270 }, $bundled_cart_items)); 271 } 287 272 return $attrs; 288 273 } … … 291 276 * @param \WC_Product $product The product to extract information from 292 277 */ 293 function simplerwc_get_product_attributes($product )278 function simplerwc_get_product_attributes($product,$bundle_type = null) 294 279 { 295 280 $attrs = [ … … 311 296 /** @var \WC_Product_Variation $product */ 312 297 $attrs['attributes'] = apply_filters('simplerwc_button_get_product_attributes', $product->get_variation_attributes(), $product); 313 } else if (is_a($product, 'WC_Product_Bundle')) { 314 /** @var \WC_Product_Bundle $product */ 315 $bundled = \WC_PB_DB::query_bundled_items([ 316 'return' => 'id=>product_id', 317 'bundle_id' => [$product->get_id()] 318 ]); 319 $attrs['bundle_configuration'] = array_reduce($bundled, function ($acc, $el) { 320 $product = \wc_get_product($el); 321 if (!$product || \is_wp_error($product)) { 322 return $acc; 323 } 324 $acc[strval($el)] = simplerwc_get_product_attributes($product); 325 return $acc; 326 }, []); 327 } 328 298 } 299 if($bundle_type){ 300 $attrs['bundle_type'] = $bundle_type; 301 $attrs['product_type'] = apply_filters('simplerwc_get_product_type_of_the_bundle',$product->get_type(), $bundle_type); 302 $attrs['bundle_configuration'] = []; 303 $bundled_products = apply_filters('simplerwc_get_all_products_linked_to_the_bundle_product',[], $product, $bundle_type); 304 foreach($bundled_products as $bundled_product){ 305 $attrs['bundle_configuration'][strval($bundled_product->get_id())] = simplerwc_get_product_attributes($bundled_product); 306 } 307 } 329 308 return $attrs; 330 309 } … … 339 318 return in_array('administrator', wp_get_current_user()->roles, true); 340 319 } 341 342 320 if (!is_array($excludedRoles = get_option('simplerwc_excluded_user_roles', [])) || !is_array($roles = wp_get_current_user()->roles)) { 343 321 return true; 344 322 } 345 346 323 return count(array_intersect($excludedRoles, $roles)) === 0; 347 324 } 348 349 function simplerwc_cart_item_is_bundled($item)350 {351 // check if is bundle product352 if (function_exists('wc_pb_is_bundled_cart_item') && \wc_pb_is_bundled_cart_item($item)) {353 return true;354 }355 356 if (array_key_exists('bundle_sell_of', $item)) {357 return true;358 }359 360 return false;361 } -
simpler-checkout/trunk/includes/compat.php
r3244572 r3257191 213 213 } 214 214 add_action('simplerwc_product_controller_request_before', 'simplerwc_rp_wcdpd_set_is_product_feed', 1, 0); 215 216 217 218 219 // BUNDLES 220 221 // WC_PB 222 function simplerwc_compat_wc_pb_cart_item_is_bundled($value, $cart_item) 223 { 224 if (function_exists('wc_pb_is_bundled_cart_item') && \wc_pb_is_bundled_cart_item($cart_item)) { 225 return true; 226 } 227 return $value; 228 } 229 add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_wc_pb_cart_item_is_bundled', 10, 2); 230 231 function simplerwc_compat_wc_pb_cart_item_is_bundle_container($value, $cart_item) 232 { 233 if (function_exists('wc_pb_is_bundle_container_cart_item') && \wc_pb_is_bundle_container_cart_item($cart_item)) { 234 return 'wc_pb'; 235 } 236 return $value; 237 } 238 add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_wc_pb_cart_item_is_bundle_container', 10, 2); 239 240 function simplerwc_compat_wc_pb_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type) 241 { 242 if($bundle_type!='wc_pb') return $value; 243 244 if (function_exists('wc_pb_get_bundled_cart_items') ){ 245 $bundled_items = \wc_pb_get_bundled_cart_items($cart_item); 246 foreach ($bundled_items as $idx => $item) { 247 $bundled_items[$idx]['quantity'] = $item['quantity'] / $cart_item['quantity']; 248 } 249 return $bundled_items; 250 } 251 252 return $value; 253 } 254 add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_wc_pb_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4); 255 256 function simplerwc_compat_wc_pb_product_is_bundle_container($value, $product) 257 { 258 if (is_a($product, 'WC_Product_Bundle')) { 259 return 'wc_pb'; 260 } 261 return $value; 262 } 263 add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_wc_pb_product_is_bundle_container', 10, 2); 264 265 function simplerwc_compat_wc_pb_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type) 266 { 267 if($bundle_type!='wc_pb') return $value; 268 269 if (is_a($product, 'WC_Product_Bundle') && class_exists('WC_PB_DB')) { 270 $bundled_products = \WC_PB_DB::query_bundled_items([ 271 'return' => 'id=>product_id', 272 'bundle_id' => [$product->get_id()] 273 ]); 274 $value = array_reduce($bundled_products, function ($acc, $el) { 275 $product = \wc_get_product($el); 276 if (!$product || \is_wp_error($product)) { 277 return $acc; 278 } 279 $acc[] = $product; 280 return $acc; 281 }, []); 282 } 283 return $value; 284 } 285 add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_wc_pb_get_all_products_linked_to_the_bundle_product', 10, 3); 286 287 function simplerwc_compat_wc_pb_add_simpler_bundle_to_cart($value, $simpler_item) 288 { 289 if($simpler_item->get_bundle_type()!='wc_pb') return $value; 290 291 if (!class_exists('WC_PB_DB')) return $value; 292 293 // the final bundle configuration to be added to cart 294 $configuration = []; 295 296 // get bundle configurations 297 $bundled = \WC_PB_DB::query_bundled_items(array( 298 'return' => 'id=>product_id', 299 'bundle_id' => array($simpler_item->get_product_id()) 300 )); 301 302 // try to match the requested configuration with one of the registered bundles 303 foreach ($simpler_item->get_bundled() as $bundle_config) { 304 $found = false; 305 foreach ($bundled as $bundle_id => $product_id) { 306 if ($bundle_config['product_id'] == $product_id) { 307 $configuration[$bundle_id] = $bundle_config; 308 $configuration[$bundle_id]['optional_selected'] = 'yes'; 309 $found = true; 310 break; 311 } 312 } 313 314 // if not found, check if variation 315 if (!$found) { 316 $product = \wc_get_product($bundle_config['product_id']); 317 if ($product->is_type('variation')) { 318 // if it's a variation try searching again with parent's id 319 /** @var \WC_Product_Variable $product */ 320 foreach ($bundled as $bundle_id => $product_id) { 321 if ($product->get_parent_id() == $product_id) { 322 $configuration[$bundle_id] = simplerwc_compat_wc_pb_construct_variation_configuration($bundle_config, $product); 323 break; 324 } 325 } 326 } 327 } 328 } 329 330 // fill configuration keys for not-selected bundled items 331 foreach ($bundled as $bundle_id => $product_id) { 332 if (!array_key_exists($bundle_id, $configuration)) { 333 $configuration[$bundle_id] = [ 334 'optional_selected' => 'no' 335 ]; 336 } 337 } 338 339 return \WC_PB()->cart->add_bundle_to_cart( 340 $simpler_item->get_product_id(), 341 $simpler_item->get_quantity(), 342 $configuration 343 ); 344 } 345 function simplerwc_compat_wc_pb_construct_variation_configuration($bundle, $product) 346 { 347 $c = $bundle; 348 foreach ($product->get_variation_attributes() as $k => $v) { 349 if (!array_key_exists($k, $bundle['attributes'])) { 350 $c['attributes'][$k] = $v; 351 } 352 } 353 $c['product_id'] = $product->get_parent_id(); 354 $c['variation_id'] = $bundle['product_id']; 355 $c['optional_selected'] = 'yes'; 356 return $c; 357 } 358 add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_wc_pb_add_simpler_bundle_to_cart', 10, 2); 359 360 function simplerwc_compat_wc_pb_get_product_type_of_the_bundle($value,$bundle_type) 361 { 362 if($bundle_type=='wc_pb') return 'bundle'; 363 return $value; 364 } 365 add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_wc_pb_get_product_type_of_the_bundle', 10, 2); 366 367 function simplerwc_compat_wc_pb_get_bundle_type_of_the_product($value,$product) 368 { 369 if($value) return $value; 370 if (is_a($product, 'WC_Product_Bundle') && class_exists('WC_PB_DB')) { 371 return 'wc_pb'; 372 } 373 return $value; 374 } 375 add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_wc_pb_get_bundle_type_of_the_product', 10, 2); 376 377 378 379 // WPC Smart Bundles 380 function simplerwc_compat_woosb_cart_item_is_bundled($value, $cart_item) 381 { 382 if (array_key_exists('woosb_parent_id',$cart_item)) { 383 return true; 384 } 385 return $value; 386 } 387 add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woosb_cart_item_is_bundled', 10, 2); 388 389 function simplerwc_compat_woosb_cart_item_is_bundle_container($value, $cart_item) 390 { 391 if (isset($cart_item['woosb_ids']) && !empty($cart_item['woosb_ids'])){ 392 return 'woosb'; 393 } 394 return $value; 395 } 396 add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woosb_cart_item_is_bundle_container', 10, 2); 397 398 function simplerwc_compat_woosb_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type) 399 { 400 if($bundle_type!='woosb') return $value; 401 402 $bundled_items = []; 403 $bundle_ids = explode(',', $cart_item['woosb_ids']); 404 405 foreach ($bundle_ids as $id) { 406 foreach ($cart->get_cart_contents() as $item) { 407 if ($item['product_id'] == $id) { 408 $bundled_items[] = $item; 409 break; 410 } 411 } 412 } 413 return $bundled_items; 414 } 415 add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woosb_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4); 416 417 function simplerwc_compat_woosb_product_is_bundle_container($value, $product) 418 { 419 if (is_a( $product, 'WC_Product_Woosb' )) { 420 return 'woosb'; 421 } 422 return $value; 423 } 424 add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woosb_product_is_bundle_container', 10, 2); 425 426 function simplerwc_compat_woosb_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type) 427 { 428 if($bundle_type!='woosb') return $value; 429 430 if (is_a( $product, 'WC_Product_Woosb' )) { 431 $bundle_items = $product->get_meta('woosb_ids'); 432 if (is_array($bundle_items)) { 433 foreach ($bundle_items as $key => $item) { 434 $id = isset($item['id']) ? intval($item['id']) : 0; 435 if ($id > 0) { 436 $bundled_product = \wc_get_product($id); 437 if ($bundled_product) { 438 $value[] = $bundled_product; 439 } 440 } 441 } 442 } 443 } 444 return $value; 445 } 446 add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woosb_get_all_products_linked_to_the_bundle_product', 10, 3); 447 448 function simplerwc_compat_woosb_add_simpler_bundle_to_cart($value, $simpler_item) 449 { 450 if($simpler_item->get_bundle_type()!='woosb') return $value; 451 452 if (!class_exists('WPCleverWoosb')) return $value; 453 454 $WPCleverWoosb = new \WPCleverWoosb; 455 $cart_data = apply_filters('simplerwc_get_cart_item_data', [], $simpler_item); 456 457 $product_id = $simpler_item->get_product_id(); 458 $quantity = $simpler_item->get_quantity(); 459 $variation_id = NULL; 460 $variation = $simpler_item->get_attributes_array(); 461 462 $cart_item_data = $WPCleverWoosb->add_cart_item_data($cart_data,$product_id); 463 if(isset($cart_item_data['woosb_ids'])){ 464 $new_woosb_ids = []; 465 $woosb_ids = explode(',',$cart_item_data['woosb_ids']); 466 foreach($woosb_ids as $woosb_id){ 467 list($pid,$pkey,$pqty) = explode('/',$woosb_id); 468 foreach($simpler_item->get_bundled() as $b_item){ 469 if($pid == $b_item['product_id']){ 470 $pqty = $b_item['quantity']; 471 $new_woosb_id = implode('/',[$pid,$pkey,$pqty]); 472 $new_woosb_ids[]=$new_woosb_id; 473 } 474 } 475 } 476 $cart_item_data['woosb_ids'] = implode(',',$new_woosb_ids); 477 } 478 479 $cart_item_key = WC()->cart->add_to_cart( 480 $product_id, 481 $quantity, 482 $variation_id, 483 $variation, 484 $cart_item_data 485 ); 486 487 $WPCleverWoosb->add_to_cart($cart_item_key, $product_id, $quantity,null,[],$cart_item_data); 488 return $cart_item_key; 489 } 490 add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woosb_add_simpler_bundle_to_cart', 10, 2); 491 492 function simplerwc_compat_woosb_before_create_quoted_product($lineItem) 493 { 494 if(isset($lineItem['woosb_price'])){ 495 $lineItem['line_total'] = $lineItem['woosb_price']; 496 $lineItem['line_subtotal'] = $lineItem['woosb_price']; 497 } 498 if(isset($lineItem['woosb_parent_id'])){ 499 $lineItem['line_total'] = 0; 500 $lineItem['line_subtotal'] = 0; 501 } 502 return $lineItem; 503 } 504 add_filter('simplerwc_before_create_quoted_product', 'simplerwc_compat_woosb_before_create_quoted_product', 10, 1); 505 506 function simplerwc_compat_woosb_get_product_type_of_the_bundle($value,$bundle_type) 507 { 508 if($bundle_type=='woosb') return 'bundle'; 509 return $value; 510 } 511 add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woosb_get_product_type_of_the_bundle', 10, 2); 512 513 function simplerwc_compat_woosb_get_bundle_type_of_the_product($value,$product) 514 { 515 if($value) return $value; 516 if (is_a( $product, 'WC_Product_Woosb' )) { 517 return 'woosb'; 518 } 519 return $value; 520 } 521 add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woosb_get_bundle_type_of_the_product', 10, 2); 522 523 524 525 // WPC Frequently Brought Together 526 function simplerwc_compat_woobt_cart_item_is_bundled($value, $cart_item) 527 { 528 if (array_key_exists('woobt_parent_id',$cart_item)) { 529 return true; 530 } 531 return $value; 532 } 533 add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woobt_cart_item_is_bundled', 10, 2); 534 535 function simplerwc_compat_woobt_cart_item_is_bundle_container($value, $cart_item) 536 { 537 if (isset($cart_item['woobt_ids']) && !empty($cart_item['woobt_ids'])){ 538 return 'woobt'; 539 } 540 return $value; 541 } 542 add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woobt_cart_item_is_bundle_container', 10, 2); 543 544 function simplerwc_compat_woobt_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type) 545 { 546 if($bundle_type!='woobt') return $value; 547 548 $bundled_items = []; 549 $bundle_ids = explode(',', $cart_item['woobt_ids']); 550 551 foreach ($bundle_ids as $bundle_line) { 552 list($id,$code,$qty) = explode('/',$bundle_line); 553 foreach ($cart->get_cart_contents() as $item) { 554 if ($item['product_id'] == $id && isset($item['woobt_parent_id']) && $item['woobt_parent_id']==$cart_item['product_id']) { 555 $bundled_items[] = $item; 556 break; 557 } 558 } 559 } 560 return $bundled_items; 561 } 562 add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woobt_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4); 563 564 function simplerwc_compat_woobt_product_is_bundle_container($value, $product) 565 { 566 $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true); 567 568 if (empty($linked_products)) return $value; 569 570 return 'woobt'; 571 } 572 add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woobt_product_is_bundle_container', 10, 2); 573 574 function simplerwc_compat_woobt_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type) 575 { 576 if($bundle_type!='woobt') return $value; 577 578 $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true); 579 580 if (empty($linked_products)) return $value; 581 582 $linked_products = maybe_unserialize($linked_products); 583 584 foreach ($linked_products as $key => $item) { 585 if (isset($item['id'])) { 586 $product = wc_get_product($item['id']); 587 if ($product) { 588 $value[]=$product; 589 } 590 } 591 } 592 return $value; 593 } 594 add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woobt_get_all_products_linked_to_the_bundle_product', 10, 3); 595 596 function simplerwc_compat_woobt_add_simpler_bundle_to_cart($value, $simpler_item) 597 { 598 if($simpler_item->get_bundle_type()!='woobt') return $value; 599 600 $main_product_metadata = apply_filters('simplerwc_get_cart_item_data', [], $simpler_item); 601 602 $main_product_id = $simpler_item->get_product_id(); 603 $main_product_cart_key = WC()->cart->add_to_cart( 604 $main_product_id, 605 $simpler_item->get_quantity(), 606 null, 607 $simpler_item->get_attributes_array(), 608 $main_product_metadata 609 ); 610 $value = $main_product_cart_key; 611 612 if (class_exists('WPCleverWoobt')) { 613 $WPCleverWoobt = new \WPCleverWoobt; 614 615 $main_product_metadata['woobt_ids'] = ''; 616 $ids = []; 617 $linked_products = $WPCleverWoobt->get_product_items( $main_product_id ); 618 foreach ($linked_products as $linked_key => $linked_product){ 619 foreach($simpler_item->get_bundled() as $simpler_bundled_item){ 620 if($simpler_bundled_item['product_id'] == $linked_product['id']){ 621 $ids[] = $simpler_bundled_item['product_id'].'/'.$linked_key.'/'.$simpler_bundled_item['quantity']; 622 } 623 } 624 } 625 $main_product_metadata['woobt_ids']=implode(',',$ids); 626 $WPCleverWoobt->add_to_cart( 627 $main_product_cart_key, 628 $main_product_id, 629 $simpler_item->get_quantity(), 630 null, 631 $simpler_item->get_attributes_array(), 632 $main_product_metadata 633 ); 634 $value = $main_product_cart_key; 635 } 636 WC()->cart->calculate_totals(); 637 return $value; 638 } 639 add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woobt_add_simpler_bundle_to_cart', 10, 2); 640 641 function simplerwc_compat_woobt_get_product_type_of_the_bundle($value,$bundle_type) 642 { 643 return $value; 644 } 645 add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woobt_get_product_type_of_the_bundle', 10, 2); 646 647 function simplerwc_compat_woobt_get_bundle_type_of_the_product($value,$product) 648 { 649 if($value) return $value; 650 $linked_products = get_post_meta($product->get_id(), 'woobt_ids', true); 651 if (!empty($linked_products)) return 'woobt'; 652 return $value; 653 } 654 add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woobt_get_bundle_type_of_the_product', 10, 2); 655 656 657 658 // WC Linked products 659 function simplerwc_compat_woocommerce_cart_item_is_bundled($value, $cart_item) 660 { 661 if (array_key_exists('bundle_sell_of',$cart_item)) { 662 return true; 663 } 664 return $value; 665 } 666 add_filter('simplerwc_cart_item_is_bundled', 'simplerwc_compat_woocommerce_cart_item_is_bundled', 10, 2); 667 668 function simplerwc_compat_woocommerce_cart_item_is_bundle_container($value, $cart_item) 669 { 670 if (isset($cart_item['bundle_sells']) && !empty($cart_item['bundle_sells'])){ 671 return 'woocommerce'; 672 } 673 return $value; 674 } 675 add_filter('simplerwc_cart_item_is_bundle_container', 'simplerwc_compat_woocommerce_cart_item_is_bundle_container', 10, 2); 676 677 function simplerwc_compat_woocommerce_get_selected_cart_items_linked_to_the_bundle_cart_item($value, $cart, $cart_item, $bundle_type) 678 { 679 if($bundle_type!='woocommerce') return $value; 680 681 $bundled_items = []; 682 $cross_sell_items = $cart_item["bundle_sells"] ?? []; 683 foreach ($cross_sell_items as $id) { 684 $bundled_items[] = $cart->get_cart_item($id); 685 } 686 return $bundled_items; 687 } 688 add_filter('simplerwc_get_selected_cart_items_linked_to_the_bundle_cart_item', 'simplerwc_compat_woocommerce_get_selected_cart_items_linked_to_the_bundle_cart_item', 10, 4); 689 690 function simplerwc_compat_woocommerce_product_is_bundle_container($value, $product) 691 { 692 $linked_products = get_post_meta($product->get_id(), 'bundle_sells', true); 693 694 if (empty($linked_products)) return $value; 695 696 return $value; 697 } 698 add_filter('simplerwc_product_is_bundle_container', 'simplerwc_compat_woocommerce_product_is_bundle_container', 10, 2); 699 700 function simplerwc_compat_woocommerce_get_all_products_linked_to_the_bundle_product($value, $product, $bundle_type) 701 { 702 if($bundle_type!='woocommerce') return $value; 703 704 return $value; 705 } 706 add_filter('simplerwc_get_all_products_linked_to_the_bundle_product', 'simplerwc_compat_woocommerce_get_all_products_linked_to_the_bundle_product', 10, 3); 707 708 function simplerwc_compat_woocommerce_add_simpler_bundle_to_cart($value, $simpler_item) 709 { 710 if($simpler_item->get_bundle_type()!='woocommerce') return $value; 711 712 $main_product_cart_key = \WC()->cart->add_to_cart( 713 $simpler_item->get_product_id(), 714 $simpler_item->get_quantity(), 715 NULL, 716 $simpler_item->get_attributes_array(), 717 apply_filters('simplerwc_get_cart_item_data', [], $simpler_item) 718 ); 719 720 // Woo Product Bundles configured through Linked Products 721 foreach ($simpler_item->get_bundled() as $bundled) { 722 \WC()->cart->add_to_cart( 723 $bundled['product_id'], 724 $bundled['quantity'], 725 NULL, 726 $bundled['attributes'], 727 apply_filters('simplerwc_get_cart_item_data', ['bundle_sell_of' => $main_product_cart_key], $bundled) 728 ); 729 } 730 if (class_exists('\WC_PB_BS_Cart') && method_exists('\WC_PB_BS_Cart', 'load_bundle_sells_into_session')) { 731 \WC_PB_BS_Cart::load_bundle_sells_into_session(\WC()->cart); 732 } 733 return $main_product_cart_key; 734 } 735 add_filter('simplerwc_add_simpler_bundle_to_cart', 'simplerwc_compat_woocommerce_add_simpler_bundle_to_cart', 10, 2); 736 737 function simplerwc_compat_woocommerce_get_product_type_of_the_bundle($value,$bundle_type) 738 { 739 return $value; 740 } 741 add_filter('simplerwc_get_product_type_of_the_bundle', 'simplerwc_compat_woocommerce_get_product_type_of_the_bundle', 10, 2); 742 743 function simplerwc_compat_woocommerce_get_bundle_type_of_the_product($value,$product) 744 { 745 if($value) return $value; 746 return 'woocommerce'; 747 } 748 add_filter('simplerwc_get_bundle_type_of_the_product', 'simplerwc_compat_woocommerce_get_bundle_type_of_the_product', 11, 2); 749 -
simpler-checkout/trunk/includes/constants.php
r3244572 r3257191 1 1 <?php 2 2 3 const SIMPLERWC_VERSION = '1.1. 1';3 const SIMPLERWC_VERSION = '1.1.2'; 4 4 5 5 function simplerwc_get_sdk_uri() -
simpler-checkout/trunk/simpler.php
r3244572 r3257191 8 8 * Description: Simpler Checkout lets your customers complete their purchases in seconds, with any payment method they want, in any device or browser and without a password. 9 9 * Tags: woocommerce, checkout, payments, conversion rate 10 * Version: 1.1. 110 * Version: 1.1.2 11 11 * Requires at least: 5.1 12 12 * Tested up to: 6.3.1 -
simpler-checkout/trunk/vendor/autoload.php
r3244572 r3257191 5 5 require_once __DIR__ . '/composer/autoload_real.php'; 6 6 7 return ComposerAutoloaderInit0 250069f9335df0d3d59ba9ce9dcfb67::getLoader();7 return ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa::getLoader(); -
simpler-checkout/trunk/vendor/composer/autoload_real.php
r3244572 r3257191 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit0 250069f9335df0d3d59ba9ce9dcfb675 class ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa 6 6 { 7 7 private static $loader; … … 25 25 require __DIR__ . '/platform_check.php'; 26 26 27 spl_autoload_register(array('ComposerAutoloaderInit0 250069f9335df0d3d59ba9ce9dcfb67', 'loadClassLoader'), true, true);27 spl_autoload_register(array('ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa', 'loadClassLoader'), true, true); 28 28 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); 29 spl_autoload_unregister(array('ComposerAutoloaderInit0 250069f9335df0d3d59ba9ce9dcfb67', 'loadClassLoader'));29 spl_autoload_unregister(array('ComposerAutoloaderInit05ed223fc9877d50fa378ef6ce7eb5aa', 'loadClassLoader')); 30 30 31 31 $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); … … 33 33 require __DIR__ . '/autoload_static.php'; 34 34 35 call_user_func(\Composer\Autoload\ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb67::getInitializer($loader));35 call_user_func(\Composer\Autoload\ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::getInitializer($loader)); 36 36 } else { 37 37 $map = require __DIR__ . '/autoload_namespaces.php'; -
simpler-checkout/trunk/vendor/composer/autoload_static.php
r3244572 r3257191 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb677 class ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( … … 86 86 { 87 87 return \Closure::bind(function () use ($loader) { 88 $loader->prefixLengthsPsr4 = ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb67::$prefixLengthsPsr4;89 $loader->prefixDirsPsr4 = ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb67::$prefixDirsPsr4;90 $loader->classMap = ComposerStaticInit0 250069f9335df0d3d59ba9ce9dcfb67::$classMap;88 $loader->prefixLengthsPsr4 = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$prefixLengthsPsr4; 89 $loader->prefixDirsPsr4 = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$prefixDirsPsr4; 90 $loader->classMap = ComposerStaticInit05ed223fc9877d50fa378ef6ce7eb5aa::$classMap; 91 91 92 92 }, null, ClassLoader::class); -
simpler-checkout/trunk/vendor/composer/installed.php
r3244572 r3257191 1 1 <?php return array( 2 2 'root' => array( 3 'pretty_version' => '1.1. 1',4 'version' => '1.1. 1.0',3 'pretty_version' => '1.1.2', 4 'version' => '1.1.2.0', 5 5 'type' => 'wordpress-plugin', 6 6 'install_path' => __DIR__ . '/../../', 7 7 'aliases' => array(), 8 'reference' => ' bb55c256e100142e4cc55de1af03ca9bcf581777',8 'reference' => '8b7d98f2bf87df11c50d0440d830606ab05ad7ef', 9 9 'name' => 'simpler-checkout/woo', 10 10 'dev' => false, … … 12 12 'versions' => array( 13 13 'simpler-checkout/woo' => array( 14 'pretty_version' => '1.1. 1',15 'version' => '1.1. 1.0',14 'pretty_version' => '1.1.2', 15 'version' => '1.1.2.0', 16 16 'type' => 'wordpress-plugin', 17 17 'install_path' => __DIR__ . '/../../', 18 18 'aliases' => array(), 19 'reference' => ' bb55c256e100142e4cc55de1af03ca9bcf581777',19 'reference' => '8b7d98f2bf87df11c50d0440d830606ab05ad7ef', 20 20 'dev_requirement' => false, 21 21 ),
Note: See TracChangeset
for help on using the changeset viewer.