Changeset 2897663
- Timestamp:
- 04/12/2023 08:17:13 AM (3 years ago)
- Location:
- share-that-cart/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (1 diff)
-
share-that-cart.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
share-that-cart/trunk/readme.txt
r2846570 r2897663 4 4 Donate link: https://www.paypal.me/Rider7991 5 5 Requires at least: 4.0 6 Tested up to: 6. 16 Tested up to: 6.2 7 7 Requires PHP: 7.0 8 8 Stable tag: trunk -
share-that-cart/trunk/share-that-cart.php
r2846574 r2897663 3 3 Plugin Name: Share That Cart 4 4 Description: This plugin allows you to share your cart via link with others. 5 Version: 1. 3.15 Version: 1.4.0 6 6 Author: Mateusz Styrna 7 7 Author URI: https://mateusz-styrna.pl/ … … 11 11 12 12 if ( !defined( 'SC_VERSION' ) ) { 13 define( 'SC_VERSION', '1. 0.1' );13 define( 'SC_VERSION', '1.2.0' ); 14 14 } 15 15 16 add_action( 'woocommerce_after_cart_contents', 'sc_button');16 add_action( 'woocommerce_after_cart_contents', 'sc_button' ); 17 17 add_action( 'wp_enqueue_scripts', 'sc_load_scripts' ); 18 add_action( 'wp_loaded', 'sc_add_products');19 register_activation_hook( __FILE__, 'sc_active');18 add_action( 'wp_loaded', 'sc_add_products' ); 19 register_activation_hook( __FILE__, 'sc_active' ); 20 20 21 21 function sc_active() { 22 22 if ( !in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 23 23 deactivate_plugins( basename( __FILE__ ) ); 24 die( _e('Plugin NOT activated: Share That Cart requires the WooCommerce plugin to be installed and active.', 'share-that-cart'));24 die( _e( 'Plugin NOT activated: Share That Cart requires the WooCommerce plugin to be installed and active.', 'share-that-cart' ) ); 25 25 return false; 26 26 } else { … … 31 31 function sc_load_scripts() { 32 32 if ( is_cart() ) { 33 wp_enqueue_style( 'sc-css', plugins_url( '/style.css', __FILE__), '', SC_VERSION, false );34 wp_enqueue_script( 'sc-js', plugins_url( '/copy.js', __FILE__), '', SC_VERSION, true );33 wp_enqueue_style( 'sc-css', plugins_url( '/style.css', __FILE__), '', SC_VERSION, false ); 34 wp_enqueue_script( 'sc-js', plugins_url( '/copy.js', __FILE__), '', SC_VERSION, true ); 35 35 } 36 36 } 37 37 38 38 function sc_button() { 39 $ items = WC()->cart->get_cart();39 $cart_items = WC()->cart->get_cart(); 40 40 $link = wc_get_cart_url(); 41 $ids = ""; 42 $quantities = ""; 43 $attr = ""; 41 $items = []; 44 42 45 foreach($items as $item => $values) { 46 $ids .= $values['product_id'] . ","; 47 $quantities .= $values['quantity'] . ","; 43 foreach( $cart_items as $cart_item => $values ) { 48 44 49 if ($values['variation_id']) { 50 $attr .= $values['product_id'] . "," . $values['variation_id'] . ","; 51 } 45 if ( $values[ 'variation_id' ] ) 46 $attr = $values[ 'variation_id' ]; 47 else 48 $attr = false; 49 50 $item = ( object ) array( 'ID' => $values[ 'product_id' ], 'QTY' => $values[ 'quantity' ], 'ATTR' => $attr ); 51 52 array_push( $items, $item ); 52 53 } 53 54 54 $link .= "?scp=" . substr($ids, 0, -1). "&scq=".substr($quantities, 0, -1) . "&sca=".substr($attr, 0, -1);55 $link .= "?scp=" . base64_encode( json_encode( $items ) ); 55 56 ?> 56 57 <tr> … … 60 61 <button id="sc__button" class="sc__button"> 61 62 <?php 62 echo _e( 'Share That Cart', 'share-that-cart');63 echo _e( 'Share That Cart', 'share-that-cart' ); 63 64 ?> 64 65 </button> … … 68 69 <div class="sc__popup" id="sc__popup"> 69 70 <?php 70 echo _e( 'Done! You can now share link to this cart by simply pasting it. It is in your clipboard!', 'share-that-cart');71 echo _e( 'Done! You can now share link to this cart by simply pasting it. It is in your clipboard!', 'share-that-cart' ); 71 72 ?> 72 73 </div> … … 74 75 } 75 76 76 function sc_secure($arr) { 77 $arrFinal = array(); 78 array_walk($arr, function($value,$key) use (&$arr, &$arrFinal){ 79 $value = intval($value); 80 if ($value != 0) { 81 array_push($arrFinal, $value); 82 } 83 }); 84 $arr = $arrFinal; 85 return $arr; 77 function sc_add_products() { 78 if ( !isset( $_GET[ 'scp' ] ) ) 79 return; 80 81 $items = json_decode( base64_decode( $_GET[ 'scp' ] ) ); 82 83 foreach ( $items as $item ) { 84 if ( $item->ATTR ) 85 WC()->cart->add_to_cart( intval( $item->ID ), intval( $item->QTY ), intval( $item->ATTR ) ); 86 else 87 WC()->cart->add_to_cart( intval( $item->ID ), intval( $item->QTY ) ); 88 } 89 90 wp_redirect( wc_get_cart_url() ); 91 exit; 86 92 } 87 93 88 function sc_add_products() { 89 if (isset($_GET['scp']) && isset($_GET['scq'])) { 90 $sc_products = sc_secure(explode(",", $_GET['scp'])); 91 var_dump($sc_products); 92 $sc_qty = sc_secure(explode(",", $_GET['scq'])); 93 var_dump($sc_qty); 94 $sc_attrs = sc_secure(explode(",", $_GET['sca'])); 95 var_dump($sc_attrs); 96 97 $i = 0; 98 while ($sc_products[$i]) { 99 100 if (array_search($sc_products[$i],$sc_attrs) !== false) { 101 WC()->cart->add_to_cart( $sc_products[$i], $sc_qty[$i], $sc_attrs[array_search( $sc_products[$i], $sc_attrs ) + 1] ); 102 \array_splice($sc_attrs, array_search($sc_products[$i],$sc_attrs), array_search($sc_products[$i],$sc_attrs)+1); 103 } 104 else { 105 WC()->cart->add_to_cart( $sc_products[$i], $sc_qty[$i] ); 106 } 107 $i++; 108 } 109 wp_redirect(wc_get_cart_url()); 110 exit; 111 } 112 } 113 114 load_plugin_textdomain('share-that-cart', false, basename( dirname( __FILE__ ) ) . '/languages' ); 94 load_plugin_textdomain( 'share-that-cart', false, basename( dirname( __FILE__ ) ) . '/languages' ); 115 95 ?>
Note: See TracChangeset
for help on using the changeset viewer.