PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.0.0
ShopBuilder – WooCommerce Builder For Elementor v1.0.0
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Modules / WishList / Wishlist.php

Wishlist.php in ShopBuilder – WooCommerce Builder For Elementor 1.0.0, at app/Modules/WishList/Wishlist.php

84 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Modules\WishList;
4
5 use RadiusTheme\SB\Traits\SingletonTrait;
6
7 // Do not allow directly accessing this file.
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit( 'This script cannot be accessed directly.' );
10 }
11
12 final class Wishlist {
13
14 const KEY = 'rtsb_wishlist';
15 // const WC_MENU_SLUG = 'wishlist';
16
17 /**
18 * @var array
19 */
20 public $settings = [];
21
22 //protected $module_id = 'wishlist';
23
24 use SingletonTrait;
25
26 private function __construct() {
27
28 new WishlistRouteV1();
29
30 WishlistFrontEnd::instance();
31
32 if ( is_user_logged_in() ) {
33 $cookie_name = WishlistFns::instance()->get_cookie_name();
34 if ( isset( $_COOKIE[ $cookie_name ] ) && is_array( json_decode( wp_unslash( $_COOKIE[ $cookie_name ] ), true ) ) ) {
35
36 $ids = WishlistFns::instance()->get_wishlist_ids();
37 $product_ids = [];
38 foreach ( $ids as $pid ) {
39 $product_ids[ $pid ] = $pid;
40 }
41 WishlistFns::instance()->update_user_wishlist_ids( $product_ids );
42 setcookie( self::KEY, '', time() - 3600, '/' );
43 }
44 }
45
46 add_action(
47 'init',
48 function () {
49 add_rewrite_endpoint( WishlistFns::WC_MENU_SLUG, EP_ROOT | EP_PAGES );
50 }
51 );
52
53 add_filter( 'woocommerce_account_menu_items', [ $this, 'add_to_menu' ], 40 );
54 add_action( 'woocommerce_account_wishlist_endpoint', [ $this, 'wishlist_content' ] );
55
56 do_action( 'rtsb/module/wishlist/loaded' );
57 }
58
59 /**
60 * @param $menu_links
61 *
62 * @return mixed
63 */
64 public function add_to_menu( $menu_links ) {
65
66 $menu_links[ WishlistFns::WC_MENU_SLUG ] = esc_html__( 'Wishlist', 'shopbuilder' );
67
68 if ( isset( $menu_links['customer-logout'] ) ) {
69
70 $logout = $menu_links['customer-logout'];
71 unset( $menu_links['customer-logout'] );
72 $menu_links['customer-logout'] = $logout;
73 } else {
74 $menu_links['customer-logout'] = esc_html__( 'Logout', 'shopbuilder' );
75 }
76
77 return $menu_links;
78 }
79
80 public function wishlist_content() {
81 echo do_shortcode( '[rtsb_wishlist]' );
82 }
83 }
84