@@ -355,56 +355,56 @@ public function get_items($items)
355
355
return $ return ;
356
356
}
357
357
358
+ public function applyDiscountData ($ data )
359
+ {
360
+ $ cart = \WC ()->cart ;
361
+ if (isset ($ data ["code " ]) && $ data ["code " ] !== "" ) {
362
+ if ($ cart ->apply_coupon ($ data ["code " ]) == true ) {
363
+ return true ;
364
+ }
365
+ }
366
+ return false ;
367
+ }
368
+
358
369
public function getCartData ()
359
370
{
360
- if (!is_null ($ cart )) {
361
- $ cart = \WC ()->cart ;
362
- $ totals = $ cart ->get_totals ();
363
- $ return = [
364
- 'total ' => $ totals ['total ' ],
365
- 'subtotal ' => $ totals ['subtotal ' ],
366
- 'tax ' => $ totals ['total_tax ' ],
367
- 'shipping ' => $ totals ['shipping_total ' ],
368
- 'currency ' => "USD " ,
369
- 'items ' => [],
370
- ];
371
+ $ cart = \WC ()->cart ;
372
+ $ totals = $ cart ->get_totals ();
373
+ $ return = [
374
+ 'total ' => $ totals ['total ' ],
375
+ 'subtotal ' => $ totals ['subtotal ' ],
376
+ 'tax ' => $ totals ['total_tax ' ],
377
+ 'shipping ' => $ totals ['shipping_total ' ],
378
+ 'currency ' => "USD " ,
379
+ 'items ' => [],
380
+ ];
371
381
372
- $ cartItems = $ cart ->get_cart_contents ();
373
- if (count ($ cartItems ) > 0 ) {
374
- foreach ($ cart ->get_cart () as $ key => $ item ) {
375
- $ cartItem = $ cart ->get_cart_item ($ key );
376
- $ attrs = '' ;
377
- if ($ cartItem ['variation_id ' ] > 0 ) {
378
- foreach ($ cartItem ['variation ' ] as $ key => $ value ) {
379
- if (strpos (strtolower ($ key ), "color " ) !== FALSE ) {
380
- $ attrs .= "color: '` {$ value }`, " ;
381
- }
382
- if (strpos (strtolower ($ key ), "size " ) !== FALSE ) {
383
- $ attrs .= "size: ` {$ value }`, " ;
384
- }
382
+ $ cartItems = $ cart ->get_cart_contents ();
383
+ if (count ($ cartItems ) > 0 ) {
384
+ foreach ($ cart ->get_cart () as $ key => $ item ) {
385
+ $ cartItem = $ cart ->get_cart_item ($ key );
386
+ $ attrs = '' ;
387
+ if ($ cartItem ['variation_id ' ] > 0 ) {
388
+ foreach ($ cartItem ['variation ' ] as $ key => $ value ) {
389
+ if (strpos (strtolower ($ key ), "color " ) !== FALSE ) {
390
+ $ attrs .= "color: '` {$ value }`, " ;
391
+ }
392
+ if (strpos (strtolower ($ key ), "size " ) !== FALSE ) {
393
+ $ attrs .= "size: ` {$ value }`, " ;
385
394
}
386
395
}
387
- $ variationId = $ cartItem ['variation_id ' ] > 0 ? $ cartItem ['variation_id ' ] : $ cartItem ['product_id ' ];
388
- $ product = $ cartItem ['data ' ];
389
- $ return ['items ' ][] = [
390
- "productid " => $ cartItem ['product_id ' ],
391
- "variationid " => $ variationId ,
392
- "sku " => $ product ->get_sku (),
393
- "quantity " => $ cartItem ['quantity ' ],
394
- "price " => $ product ->get_price (),
395
- "{$ attrs }name " => $ product ->get_name ()
396
- ];
397
396
}
397
+ $ variationId = $ cartItem ['variation_id ' ] > 0 ? $ cartItem ['variation_id ' ] : $ cartItem ['product_id ' ];
398
+ $ product = $ cartItem ['data ' ];
399
+ $ return ['items ' ][] = [
400
+ "productid " => $ cartItem ['product_id ' ],
401
+ "variationid " => $ variationId ,
402
+ "sku " => $ product ->get_sku (),
403
+ "quantity " => $ cartItem ['quantity ' ],
404
+ "price " => $ product ->get_price (),
405
+ "{$ attrs }name " => $ product ->get_name ()
406
+ ];
398
407
}
399
- } else {
400
- $ return = [
401
- 'total ' => 0 ,
402
- 'subtotal ' => 0 ,
403
- 'tax ' => 0 ,
404
- 'shipping ' => 0 ,
405
- 'currency ' => "USD " ,
406
- 'items ' => [],
407
- ];
408
408
}
409
409
return $ return ;
410
410
}
@@ -432,40 +432,38 @@ public function getConversionTrackingCodes()
432
432
}
433
433
434
434
$ cart = \WC ()->cart ;
435
- if (!is_null ($ cart )) {
436
- $ totals = $ cart ->get_totals ();
437
- $ code .= 'juapp("cart", {
435
+ $ totals = $ cart ->get_totals ();
436
+ $ code .= 'juapp("cart", {
438
437
total: ' . $ totals ['total ' ] . ',
439
438
subtotal: ' . $ totals ['subtotal ' ] . ',
440
439
tax: ' . $ totals ['total_tax ' ] . ',
441
440
shipping: ' . $ totals ['shipping_total ' ] . ',
442
441
currency:"USD",
443
442
}
444
443
); ' ;
445
- $ cartItems = $ cart ->get_cart_contents ();
446
- if (count ($ cartItems ) > 0 ) {
447
- $ code .= "juapp('cartItems', [ " ;
448
- foreach ($ cart ->get_cart () as $ key => $ item ) {
449
- $ cartItem = $ cart ->get_cart_item ($ key );
450
- $ attrs = '' ;
451
- if ($ cartItem ['variation_id ' ] > 0 ) {
452
- foreach ($ cartItem ['variation ' ] as $ key => $ value ) {
453
- if (strpos (strtolower ($ key ), "color " ) !== FALSE ) {
454
- $ attrs .= "color: ` {$ value }`, " ;
455
- }
456
- if (strpos (strtolower ($ key ), "size " ) !== FALSE ) {
457
- $ attrs .= "size: ` {$ value }`, " ;
458
- }
444
+ $ cartItems = $ cart ->get_cart_contents ();
445
+ if (count ($ cartItems ) > 0 ) {
446
+ $ code .= "juapp('cartItems', [ " ;
447
+ foreach ($ cart ->get_cart () as $ key => $ item ) {
448
+ $ cartItem = $ cart ->get_cart_item ($ key );
449
+ $ attrs = '' ;
450
+ if ($ cartItem ['variation_id ' ] > 0 ) {
451
+ foreach ($ cartItem ['variation ' ] as $ key => $ value ) {
452
+ if (strpos (strtolower ($ key ), "color " ) !== FALSE ) {
453
+ $ attrs .= "color: ` {$ value }`, " ;
454
+ }
455
+ if (strpos (strtolower ($ key ), "size " ) !== FALSE ) {
456
+ $ attrs .= "size: ` {$ value }`, " ;
459
457
}
460
458
}
461
- $ variationId = $ cartItem ['variation_id ' ] > 0 ? $ cartItem ['variation_id ' ] : $ cartItem ['product_id ' ];
462
- $ product = $ cartItem ['data ' ];
463
- $ code .= "
464
- { productid: ' {$ cartItem ['product_id ' ]}', variationid: ' {$ variationId }', sku:` {$ product ->get_sku ()}`, quantity: {$ cartItem ['quantity ' ]}, price: {$ product ->get_price ()}, {$ attrs }name: ` {$ product ->get_name ()}`}, " ;
465
459
}
466
- $ code = substr ($ code , 0 , -1 );
467
- $ code .= "]) " ;
460
+ $ variationId = $ cartItem ['variation_id ' ] > 0 ? $ cartItem ['variation_id ' ] : $ cartItem ['product_id ' ];
461
+ $ product = $ cartItem ['data ' ];
462
+ $ code .= "
463
+ { productid: ' {$ cartItem ['product_id ' ]}', variationid: ' {$ variationId }', sku:` {$ product ->get_sku ()}`, quantity: {$ cartItem ['quantity ' ]}, price: {$ product ->get_price ()}, {$ attrs }name: ` {$ product ->get_name ()}`}, " ;
468
464
}
465
+ $ code = substr ($ code , 0 , -1 );
466
+ $ code .= "]) " ;
469
467
}
470
468
return $ code ;
471
469
}
0 commit comments