data-stores
3 years ago
legacy
4 years ago
widgets
3 years ago
class-yith-wcwl-admin.php
3 years ago
class-yith-wcwl-ajax-handler.php
3 years ago
class-yith-wcwl-cron.php
3 years ago
class-yith-wcwl-exception.php
4 years ago
class-yith-wcwl-form-handler.php
3 years ago
class-yith-wcwl-frontend.php
3 years ago
class-yith-wcwl-install.php
4 years ago
class-yith-wcwl-privacy.php
3 years ago
class-yith-wcwl-session.php
3 years ago
class-yith-wcwl-shortcode.php
3 years ago
class-yith-wcwl-wishlist-factory.php
3 years ago
class-yith-wcwl-wishlist-item.php
3 years ago
class-yith-wcwl-wishlist.php
3 years ago
class-yith-wcwl.php
3 years ago
functions-yith-wcwl.php
3 years ago
class-yith-wcwl-shortcode.php
937 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Shortcodes class |
| 4 | * |
| 5 | * @author YITH |
| 6 | * @package YITH\Wishlist\Classes |
| 7 | * @version 3.0.0 |
| 8 | */ |
| 9 | |
| 10 | if ( ! defined( 'YITH_WCWL' ) ) { |
| 11 | exit; |
| 12 | } // Exit if accessed directly |
| 13 | |
| 14 | if ( ! class_exists( 'YITH_WCWL_Shortcode' ) ) { |
| 15 | /** |
| 16 | * YITH WCWL Shortcodes |
| 17 | * |
| 18 | * @since 1.0.0 |
| 19 | */ |
| 20 | class YITH_WCWL_Shortcode { |
| 21 | |
| 22 | /** |
| 23 | * Init shortcodes available for the plugin |
| 24 | * |
| 25 | * @return void |
| 26 | */ |
| 27 | public static function init() { |
| 28 | // register shortcodes. |
| 29 | add_shortcode( 'yith_wcwl_wishlist', array( 'YITH_WCWL_Shortcode', 'wishlist' ) ); |
| 30 | add_shortcode( 'yith_wcwl_add_to_wishlist', array( 'YITH_WCWL_Shortcode', 'add_to_wishlist' ) ); |
| 31 | |
| 32 | // register gutenberg blocks. |
| 33 | add_action( 'init', array( 'YITH_WCWL_Shortcode', 'register_gutenberg_blocks' ) ); |
| 34 | add_action( 'yith_plugin_fw_gutenberg_before_do_shortcode', array( 'YITH_WCWL_Shortcode', 'fix_for_gutenberg_blocks' ), 10, 1 ); |
| 35 | |
| 36 | // register elementor widgets. |
| 37 | add_action( 'init', array( 'YITH_WCWL_Shortcode', 'init_elementor_widgets' ) ); |
| 38 | } |
| 39 | |
| 40 | /* === GUTENBERG BLOCKS === */ |
| 41 | |
| 42 | /** |
| 43 | * Register available gutenberg blocks |
| 44 | * |
| 45 | * @return void |
| 46 | */ |
| 47 | public static function register_gutenberg_blocks() { |
| 48 | $blocks = array( |
| 49 | 'yith-wcwl-add-to-wishlist' => array( |
| 50 | 'style' => 'yith-wcwl-main', |
| 51 | 'script' => 'jquery-yith-wcwl', |
| 52 | 'title' => _x( 'YITH Add to wishlist', '[gutenberg]: block name', 'yith-woocommerce-wishlist' ), |
| 53 | 'description' => _x( 'Shows Add to wishlist button', '[gutenberg]: block description', 'yith-woocommerce-wishlist' ), |
| 54 | 'shortcode_name' => 'yith_wcwl_add_to_wishlist', |
| 55 | 'attributes' => array( |
| 56 | 'product_id' => array( |
| 57 | 'type' => 'text', |
| 58 | 'label' => __( 'ID of the product to add to the wishlist (leave empty to use the global product)', 'yith-woocommerce-wishlist' ), |
| 59 | 'default' => '', |
| 60 | ), |
| 61 | 'wishlist_url' => array( |
| 62 | 'type' => 'text', |
| 63 | 'label' => __( 'URL of the wishlist page (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ), |
| 64 | 'default' => '', |
| 65 | ), |
| 66 | 'label' => array( |
| 67 | 'type' => 'text', |
| 68 | 'label' => __( 'Button label (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ), |
| 69 | 'default' => '', |
| 70 | ), |
| 71 | 'browse_wishlist_text' => array( |
| 72 | 'type' => 'text', |
| 73 | 'label' => __( '"Browse wishlist" label (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ), |
| 74 | 'default' => '', |
| 75 | ), |
| 76 | 'already_in_wishslist_text' => array( |
| 77 | 'type' => 'text', |
| 78 | 'label' => __( '"Product already in wishlist" label (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ), |
| 79 | 'default' => '', |
| 80 | ), |
| 81 | 'product_added_text' => array( |
| 82 | 'type' => 'text', |
| 83 | 'label' => __( '"Product added to wishlist" label (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ), |
| 84 | 'default' => '', |
| 85 | ), |
| 86 | 'icon' => array( |
| 87 | 'type' => 'text', |
| 88 | 'label' => __( 'Icon for the button (use any FontAwesome valid class, or leave empty to use the default settings)', 'yith-woocommerce-wishlist' ), |
| 89 | 'default' => '', |
| 90 | ), |
| 91 | 'link_classes' => array( |
| 92 | 'type' => 'text', |
| 93 | 'label' => __( 'Additional CSS classes for the button (leave empty to use the default settings)', 'yith-woocommerce-wishlist' ), |
| 94 | 'default' => '', |
| 95 | ), |
| 96 | ), |
| 97 | ), |
| 98 | 'yith-wcwl-wishlist' => array( |
| 99 | 'style' => 'yith-wcwl-main', |
| 100 | 'script' => 'jquery-yith-wcwl', |
| 101 | 'title' => _x( 'YITH Wishlist', '[gutenberg]: block name', 'yith-woocommerce-wishlist' ), |
| 102 | 'description' => _x( 'Shows a list of products in wishlist', '[gutenberg]: block description', 'yith-woocommerce-wishlist' ), |
| 103 | 'shortcode_name' => 'yith_wcwl_wishlist', |
| 104 | 'attributes' => array( |
| 105 | 'pagination' => array( |
| 106 | 'type' => 'select', |
| 107 | 'label' => __( 'Choose whether to paginate items in the wishlist or show them all', 'yith-woocommerce-wishlist' ), |
| 108 | 'default' => 'no', |
| 109 | 'options' => array( |
| 110 | 'yes' => __( 'Paginate', 'yith-woocommerce-wishlist' ), |
| 111 | 'no' => __( 'Do not paginate', 'yith-woocommerce-wishlist' ), |
| 112 | ), |
| 113 | ), |
| 114 | 'per_page' => array( |
| 115 | 'type' => 'number', |
| 116 | 'label' => __( 'Number of items to show per page', 'yith-woocommerce-wishlist' ), |
| 117 | 'default' => '5', |
| 118 | ), |
| 119 | 'wishlist_id' => array( |
| 120 | 'type' => 'text', |
| 121 | 'label' => __( 'ID of the wishlist to show (e.g. K6EOWXB888ZD)', 'yith-woocommerce-wishlist' ), |
| 122 | 'default' => '', |
| 123 | ), |
| 124 | ), |
| 125 | ), |
| 126 | ); |
| 127 | |
| 128 | yith_plugin_fw_gutenberg_add_blocks( $blocks ); |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Fix preview of Gutenberg blocks at backend |
| 133 | * |
| 134 | * @param string $shortcode Shortcode to render. |
| 135 | * @return void |
| 136 | */ |
| 137 | public static function fix_for_gutenberg_blocks( $shortcode ) { |
| 138 | if ( strpos( $shortcode, '[yith_wcwl_add_to_wishlist' ) !== false ) { |
| 139 | if ( strpos( $shortcode, 'product_id=""' ) !== false ) { |
| 140 | $products = wc_get_products( |
| 141 | array( |
| 142 | 'type' => 'simple', |
| 143 | 'limit' => 1, |
| 144 | ) |
| 145 | ); |
| 146 | |
| 147 | if ( ! empty( $products ) ) { |
| 148 | global $product; |
| 149 | $product = array_shift( $products ); |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /* === ELEMENTOR WIDGETS === */ |
| 156 | |
| 157 | /** |
| 158 | * Register custom widgets for Elementor |
| 159 | * |
| 160 | * @return void |
| 161 | */ |
| 162 | public static function init_elementor_widgets() { |
| 163 | // check if elementor is active. |
| 164 | if ( ! defined( 'ELEMENTOR_VERSION' ) ) { |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | // include widgets. |
| 169 | include_once YITH_WCWL_INC . 'widgets/elementor/class-yith-wcwl-elementor-add-to-wishlist.php'; |
| 170 | include_once YITH_WCWL_INC . 'widgets/elementor/class-yith-wcwl-elementor-wishlist.php'; |
| 171 | |
| 172 | $register_widget_hook = version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ? 'elementor/widgets/register' : 'elementor/widgets/widgets_registered'; |
| 173 | |
| 174 | // register widgets. |
| 175 | add_action( $register_widget_hook, array( 'YITH_WCWL_Shortcode', 'register_elementor_widgets' ) ); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Register Elementor Widgets |
| 180 | * |
| 181 | * @return void |
| 182 | */ |
| 183 | public static function register_elementor_widgets() { |
| 184 | $widgets_manager = \Elementor\Plugin::instance()->widgets_manager; |
| 185 | |
| 186 | if ( is_callable( array( $widgets_manager, 'register' ) ) ) { |
| 187 | $widgets_manager->register( new YITH_WCWL_Elementor_Add_To_Wishlist() ); |
| 188 | $widgets_manager->register( new YITH_WCWL_Elementor_Wishlist() ); |
| 189 | } else { |
| 190 | $widgets_manager->register_widget_type( new YITH_WCWL_Elementor_Add_To_Wishlist() ); |
| 191 | $widgets_manager->register_widget_type( new YITH_WCWL_Elementor_Wishlist() ); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /* === SHORTCODES == */ |
| 196 | |
| 197 | /** |
| 198 | * Print the wishlist HTML. |
| 199 | * |
| 200 | * @param array $atts Array of attributes for the shortcode. |
| 201 | * @param string $content Shortcode content (none expected). |
| 202 | * @return string Rendered shortcode |
| 203 | * |
| 204 | * @since 1.0.0 |
| 205 | */ |
| 206 | public static function wishlist( $atts, $content = null ) { |
| 207 | global $yith_wcwl_is_wishlist, $yith_wcwl_wishlist_token; |
| 208 | |
| 209 | $atts = shortcode_atts( |
| 210 | array( |
| 211 | 'per_page' => 5, |
| 212 | 'current_page' => 1, |
| 213 | 'pagination' => 'no', |
| 214 | 'wishlist_id' => get_query_var( 'wishlist_id', false ), |
| 215 | 'action_params' => get_query_var( YITH_WCWL()->wishlist_param, false ), |
| 216 | 'no_interactions' => 'no', |
| 217 | 'layout' => '', |
| 218 | ), |
| 219 | $atts |
| 220 | ); |
| 221 | |
| 222 | /** |
| 223 | * Extracted variables: |
| 224 | * |
| 225 | * @var $per_page int |
| 226 | * @var $current_page int |
| 227 | * @var $pagination string |
| 228 | * @var $wishlist_id int |
| 229 | * @var $action_params array |
| 230 | * @var $no_interactions string |
| 231 | * @var $layout string |
| 232 | */ |
| 233 | extract( $atts ); // phpcs:ignore |
| 234 | |
| 235 | // retrieve options from query string. |
| 236 | /** |
| 237 | * APPLY_FILTERS: yith_wcwl_current_wishlist_view_params |
| 238 | * |
| 239 | * Filter the array of parameters to see the current wishlist. |
| 240 | * |
| 241 | * @param array $params Array of parameters |
| 242 | * |
| 243 | * @return array |
| 244 | */ |
| 245 | $action_params = explode( '/', apply_filters( 'yith_wcwl_current_wishlist_view_params', $action_params ) ); |
| 246 | $action = ( isset( $action_params[0] ) ) ? $action_params[0] : 'view'; |
| 247 | |
| 248 | // retrieve options from db. |
| 249 | $default_wishlist_title = get_option( 'yith_wcwl_wishlist_title' ); |
| 250 | $show_price = 'yes' === get_option( 'yith_wcwl_price_show' ); |
| 251 | $show_stock = 'yes' === get_option( 'yith_wcwl_stock_show' ); |
| 252 | $show_date_added = 'yes' === get_option( 'yith_wcwl_show_dateadded' ); |
| 253 | $show_add_to_cart = 'yes' === get_option( 'yith_wcwl_add_to_cart_show' ); |
| 254 | $show_remove_product = 'yes' === get_option( 'yith_wcwl_show_remove', 'yes' ); |
| 255 | $show_variation = 'yes' === get_option( 'yith_wcwl_variation_show' ); |
| 256 | $repeat_remove_button = 'yes' === get_option( 'yith_wcwl_repeat_remove_button' ); |
| 257 | $add_to_cart_label = get_option( 'yith_wcwl_add_to_cart_text', __( 'Add to cart', 'yith-woocommerce-wishlist' ) ); |
| 258 | $price_excluding_tax = 'excl' === get_option( 'woocommerce_tax_display_cart' ); |
| 259 | $ajax_loading = 'yes' === get_option( 'yith_wcwl_ajax_enable', 'no' ); |
| 260 | |
| 261 | // icons. |
| 262 | $icon = get_option( 'yith_wcwl_add_to_wishlist_icon' ); |
| 263 | |
| 264 | if ( 'custom' === $icon ) { |
| 265 | $custom_icon = get_option( 'yith_wcwl_add_to_wishlist_custom_icon' ); |
| 266 | |
| 267 | /** |
| 268 | * APPLY_FILTERS: yith_wcwl_custom_icon_alt |
| 269 | * |
| 270 | * Filter the alternative text for the heading icon in the widget. |
| 271 | * |
| 272 | * @param string $text Alternative text |
| 273 | * |
| 274 | * @return string |
| 275 | */ |
| 276 | $custom_icon_alt = apply_filters( 'yith_wcwl_custom_icon_alt', '' ); |
| 277 | |
| 278 | /** |
| 279 | * APPLY_FILTERS: yith_wcwl_custom_width |
| 280 | * |
| 281 | * Filter the width for the heading icon in the widget. |
| 282 | * |
| 283 | * @param string $width Icon width |
| 284 | * |
| 285 | * @return string |
| 286 | */ |
| 287 | $custom_icon_width = apply_filters( 'yith_wcwl_custom_width', '32' ); |
| 288 | |
| 289 | $heading_icon = '<img src="' . esc_url( $custom_icon ) . '" alt="' . esc_attr( $custom_icon_alt ) . '" width="' . esc_attr( $custom_icon_width ) . '" />'; |
| 290 | } else { |
| 291 | $heading_icon = ! empty( $icon ) ? '<i class="fa ' . esc_attr( $icon ) . '"></i>' : ''; |
| 292 | } |
| 293 | |
| 294 | // init params needed to load correct template. |
| 295 | $template_part = 'view'; |
| 296 | $no_interactions = 'yes' === $no_interactions; |
| 297 | $additional_params = array( |
| 298 | // wishlist data. |
| 299 | 'wishlist' => false, |
| 300 | 'is_default' => true, // @deprecated since 3.0.7 |
| 301 | 'is_custom_list' => false, |
| 302 | 'wishlist_token' => '', |
| 303 | 'wishlist_id' => false, |
| 304 | 'is_private' => false, |
| 305 | |
| 306 | // wishlist items. |
| 307 | 'count' => 0, |
| 308 | 'wishlist_items' => array(), |
| 309 | |
| 310 | // page data. |
| 311 | 'page_title' => $default_wishlist_title, |
| 312 | 'default_wishlsit_title' => $default_wishlist_title, |
| 313 | 'current_page' => $current_page, |
| 314 | 'page_links' => false, |
| 315 | 'layout' => $layout, |
| 316 | |
| 317 | // user data. |
| 318 | 'is_user_logged_in' => is_user_logged_in(), |
| 319 | 'is_user_owner' => true, |
| 320 | 'can_user_edit_title' => false, |
| 321 | |
| 322 | // view data. |
| 323 | 'no_interactions' => $no_interactions, |
| 324 | 'show_price' => $show_price, |
| 325 | 'show_dateadded' => $show_date_added, |
| 326 | 'show_stock_status' => $show_stock, |
| 327 | 'show_add_to_cart' => $show_add_to_cart && ! $no_interactions, |
| 328 | 'show_remove_product' => $show_remove_product && ! $no_interactions, |
| 329 | 'add_to_cart_text' => $add_to_cart_label, |
| 330 | 'show_ask_estimate_button' => false, |
| 331 | 'ask_estimate_url' => '', |
| 332 | 'price_excl_tax' => $price_excluding_tax, |
| 333 | 'show_cb' => false, |
| 334 | 'show_quantity' => false, |
| 335 | 'show_variation' => $show_variation, |
| 336 | 'show_price_variations' => false, |
| 337 | 'show_update' => false, |
| 338 | 'enable_drag_n_drop' => false, |
| 339 | 'enable_add_all_to_cart' => false, |
| 340 | 'move_to_another_wishlist' => false, |
| 341 | 'repeat_remove_button' => $repeat_remove_button && ! $no_interactions, |
| 342 | 'show_last_column' => $show_date_added || ( $show_add_to_cart && ! $no_interactions ) || ( $repeat_remove_button && ! $no_interactions ), |
| 343 | |
| 344 | // wishlist icon. |
| 345 | 'heading_icon' => $heading_icon, |
| 346 | |
| 347 | // share data. |
| 348 | 'share_enabled' => false, |
| 349 | |
| 350 | // template data. |
| 351 | 'template_part' => $template_part, |
| 352 | 'additional_info' => false, |
| 353 | 'available_multi_wishlist' => false, |
| 354 | 'users_wishlists' => array(), |
| 355 | 'form_action' => esc_url( YITH_WCWL()->get_wishlist_url( 'view' ) ), |
| 356 | ); |
| 357 | |
| 358 | $wishlist = YITH_WCWL_Wishlist_Factory::get_current_wishlist( $atts ); |
| 359 | |
| 360 | if ( $wishlist && $wishlist->current_user_can( 'view' ) ) { |
| 361 | // set global wishlist token. |
| 362 | $yith_wcwl_wishlist_token = $wishlist->get_token(); |
| 363 | |
| 364 | // retrieve wishlist params. |
| 365 | $is_user_owner = $wishlist->is_current_user_owner(); |
| 366 | $count = $wishlist->count_items(); |
| 367 | $offset = 0; |
| 368 | |
| 369 | // sets current page, number of pages and element offset. |
| 370 | $queried_page = get_query_var( 'paged' ); |
| 371 | $current_page = max( 1, $queried_page ? $queried_page : $current_page ); |
| 372 | |
| 373 | // sets variables for pagination, if shortcode atts is set to yes. |
| 374 | if ( 'yes' === $pagination && ! $no_interactions && $count > 1 ) { |
| 375 | $pages = ceil( $count / $per_page ); |
| 376 | |
| 377 | if ( $current_page > $pages ) { |
| 378 | $current_page = $pages; |
| 379 | } |
| 380 | |
| 381 | $offset = ( $current_page - 1 ) * $per_page; |
| 382 | |
| 383 | if ( $pages > 1 ) { |
| 384 | $page_links = paginate_links( |
| 385 | array( |
| 386 | 'base' => esc_url( add_query_arg( array( 'paged' => '%#%' ), $wishlist->get_url() ) ), |
| 387 | 'format' => '?paged=%#%', |
| 388 | 'current' => $current_page, |
| 389 | 'total' => $pages, |
| 390 | 'show_all' => true, |
| 391 | ) |
| 392 | ); |
| 393 | } |
| 394 | } else { |
| 395 | $per_page = 0; |
| 396 | } |
| 397 | |
| 398 | // retrieve items to print. |
| 399 | $wishlist_items = $wishlist->get_items( $per_page, $offset ); |
| 400 | |
| 401 | // retrieve wishlist information. |
| 402 | $is_default = $wishlist->get_is_default(); |
| 403 | $wishlist_token = $wishlist->get_token(); |
| 404 | $wishlist_title = $wishlist->get_formatted_name(); |
| 405 | |
| 406 | $additional_params = wp_parse_args( |
| 407 | array( |
| 408 | // wishlist items. |
| 409 | 'count' => $count, |
| 410 | 'wishlist_items' => $wishlist_items, |
| 411 | |
| 412 | // wishlist data. |
| 413 | 'wishlist' => $wishlist, |
| 414 | 'is_default' => $is_default, |
| 415 | 'is_custom_list' => $is_user_owner && ! $no_interactions, // @deprecated since 3.0.7 |
| 416 | 'wishlist_token' => $wishlist_token, |
| 417 | 'wishlist_id' => $wishlist->get_id(), |
| 418 | 'is_private' => $wishlist->has_privacy( 'private' ), |
| 419 | 'ajax_loading' => $ajax_loading, |
| 420 | |
| 421 | // page data. |
| 422 | 'page_title' => $wishlist_title, |
| 423 | 'current_page' => $current_page, |
| 424 | 'page_links' => isset( $page_links ) && ! $no_interactions ? $page_links : false, |
| 425 | |
| 426 | // user data. |
| 427 | 'is_user_owner' => $is_user_owner, |
| 428 | 'can_user_edit_title' => $wishlist->current_user_can( 'update_wishlist' ) && ! $no_interactions, |
| 429 | |
| 430 | // view data. |
| 431 | 'show_remove_product' => $show_remove_product && $wishlist->current_user_can( 'remove_from_wishlist' ) && ! $no_interactions, |
| 432 | 'repeat_remove_button' => $repeat_remove_button && $wishlist->current_user_can( 'remove_from_wishlist' ) && ! $no_interactions, |
| 433 | |
| 434 | // template data. |
| 435 | 'form_action' => $wishlist->get_url(), |
| 436 | ), |
| 437 | $additional_params |
| 438 | ); |
| 439 | |
| 440 | // share options. |
| 441 | $enable_share = 'yes' === get_option( 'yith_wcwl_enable_share' ) && ! $wishlist->has_privacy( 'private' ); |
| 442 | $share_facebook_enabled = 'yes' === get_option( 'yith_wcwl_share_fb' ); |
| 443 | $share_twitter_enabled = 'yes' === get_option( 'yith_wcwl_share_twitter' ); |
| 444 | $share_pinterest_enabled = 'yes' === get_option( 'yith_wcwl_share_pinterest' ); |
| 445 | $share_email_enabled = 'yes' === get_option( 'yith_wcwl_share_email' ); |
| 446 | $share_whatsapp_enabled = 'yes' === get_option( 'yith_wcwl_share_whatsapp' ); |
| 447 | $share_url_enabled = 'yes' === get_option( 'yith_wcwl_share_url' ); |
| 448 | |
| 449 | // we want spaces to be encoded as + instead of %20, so we use urlencode instead of rawurlencode. |
| 450 | // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode |
| 451 | if ( ! $no_interactions && $enable_share && ( $share_facebook_enabled || $share_twitter_enabled || $share_pinterest_enabled || $share_email_enabled || $share_whatsapp_enabled || $share_url_enabled ) ) { |
| 452 | /** |
| 453 | * APPLY_FILTERS: yith_wcwl_socials_share_title |
| 454 | * |
| 455 | * Filter the title to share the wishlist on the different socials. |
| 456 | * |
| 457 | * @param string $share_title Share title |
| 458 | * |
| 459 | * @return string |
| 460 | */ |
| 461 | $share_title = apply_filters( 'yith_wcwl_socials_share_title', __( 'Share on:', 'yith-woocommerce-wishlist' ) ); |
| 462 | |
| 463 | /** |
| 464 | * APPLY_FILTERS: yith_wcwl_shortcode_share_link_url |
| 465 | * |
| 466 | * Filter the wishlist URL to share. |
| 467 | * |
| 468 | * @param string $share_link_url Share link URL |
| 469 | * @param YITH_WCWL_Wishlist $wishlist Wishlist object |
| 470 | * |
| 471 | * @return string |
| 472 | */ |
| 473 | $share_link_url = apply_filters( 'yith_wcwl_shortcode_share_link_url', $wishlist->get_url(), $wishlist ); |
| 474 | |
| 475 | /** |
| 476 | * APPLY_FILTERS: yith_wcwl_share_title |
| 477 | * |
| 478 | * Filter the title to share the wishlist. |
| 479 | * |
| 480 | * @param string $share_title Share title |
| 481 | * @param YITH_WCWL_Wishlist $wishlist Wishlist object |
| 482 | * |
| 483 | * @return string |
| 484 | */ |
| 485 | $share_link_title = apply_filters( 'yith_wcwl_share_title', urlencode( get_option( 'yith_wcwl_socials_title' ) ), $wishlist ); |
| 486 | $share_summary = urlencode( str_replace( '%wishlist_url%', $share_link_url, get_option( 'yith_wcwl_socials_text' ) ) ); |
| 487 | |
| 488 | $share_atts = array( |
| 489 | 'share_facebook_enabled' => $share_facebook_enabled, |
| 490 | 'share_twitter_enabled' => $share_twitter_enabled, |
| 491 | 'share_pinterest_enabled' => $share_pinterest_enabled, |
| 492 | 'share_email_enabled' => $share_email_enabled, |
| 493 | 'share_whatsapp_enabled' => $share_whatsapp_enabled, |
| 494 | 'share_url_enabled' => $share_url_enabled, |
| 495 | 'share_title' => $share_title, |
| 496 | 'share_link_url' => $share_link_url, |
| 497 | 'share_link_title' => $share_link_title, |
| 498 | ); |
| 499 | |
| 500 | if ( $share_facebook_enabled ) { |
| 501 | $share_facebook_icon = get_option( 'yith_wcwl_fb_button_icon', 'fa-facebook' ); |
| 502 | $share_facebook_custom_icon = get_option( 'yith_wcwl_fb_button_custom_icon' ); |
| 503 | |
| 504 | if ( ! in_array( $share_facebook_icon, array( 'none', 'custom' ), true ) ) { |
| 505 | $share_atts['share_facebook_icon'] = "<i class='fa {$share_facebook_icon}'></i>"; |
| 506 | } elseif ( 'custom' === $share_facebook_icon && $share_facebook_custom_icon ) { |
| 507 | $alt_text = __( 'Share on Facebook', 'yith-woocommerce-wishlist' ); |
| 508 | $share_atts['share_facebook_icon'] = "<img src='{$share_facebook_custom_icon}' alt='{$alt_text}'/>"; |
| 509 | } else { |
| 510 | $share_atts['share_facebook_icon'] = ''; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | if ( $share_twitter_enabled ) { |
| 515 | $share_twitter_summary = urlencode( str_replace( '%wishlist_url%', '', get_option( 'yith_wcwl_socials_text' ) ) ); |
| 516 | $share_twitter_icon = get_option( 'yith_wcwl_tw_button_icon', 'fa-twitter' ); |
| 517 | $share_twitter_custom_icon = get_option( 'yith_wcwl_tw_button_custom_icon' ); |
| 518 | |
| 519 | $share_atts['share_twitter_summary'] = $share_twitter_summary; |
| 520 | |
| 521 | if ( ! in_array( $share_twitter_icon, array( 'none', 'custom' ), true ) ) { |
| 522 | $share_atts['share_twitter_icon'] = "<i class='fa {$share_twitter_icon}'></i>"; |
| 523 | } elseif ( 'custom' === $share_twitter_icon && $share_twitter_custom_icon ) { |
| 524 | $alt_text = __( 'Tweet on Twitter', 'yith-woocommerce-wishlist' ); |
| 525 | $share_atts['share_twitter_icon'] = "<img src='{$share_twitter_custom_icon}' alt='{$alt_text}'/>"; |
| 526 | } else { |
| 527 | $share_atts['share_twitter_icon'] = ''; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | if ( $share_pinterest_enabled ) { |
| 532 | $share_image_url = urlencode( get_option( 'yith_wcwl_socials_image_url' ) ); |
| 533 | $share_pinterest_icon = get_option( 'yith_wcwl_pr_button_icon', 'fa-pinterest' ); |
| 534 | $share_pinterest_custom_icon = get_option( 'yith_wcwl_pr_button_custom_icon' ); |
| 535 | |
| 536 | $share_atts['share_summary'] = $share_summary; |
| 537 | $share_atts['share_image_url'] = $share_image_url; |
| 538 | |
| 539 | if ( ! in_array( $share_pinterest_icon, array( 'none', 'custom' ), true ) ) { |
| 540 | $share_atts['share_pinterest_icon'] = "<i class='fa {$share_pinterest_icon}'></i>"; |
| 541 | } elseif ( 'custom' === $share_pinterest_icon && $share_pinterest_custom_icon ) { |
| 542 | $alt_text = __( 'Pin on Pinterest', 'yith-woocommerce-wishlist' ); |
| 543 | $share_atts['share_pinterest_icon'] = "<img src='{$share_pinterest_custom_icon}' alt='{$alt_text}'/>"; |
| 544 | } else { |
| 545 | $share_atts['share_pinterest_icon'] = ''; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | if ( $share_email_enabled ) { |
| 550 | $share_email_icon = get_option( 'yith_wcwl_em_button_icon', 'fa-email' ); |
| 551 | $share_email_custom_icon = get_option( 'yith_wcwl_em_button_custom_icon' ); |
| 552 | |
| 553 | if ( ! in_array( $share_email_icon, array( 'none', 'custom' ), true ) ) { |
| 554 | $share_atts['share_email_icon'] = "<i class='fa {$share_email_icon}'></i>"; |
| 555 | } elseif ( 'custom' === $share_email_icon && $share_email_custom_icon ) { |
| 556 | $alt_text = __( 'Share via email', 'yith-woocommerce-wishlist' ); |
| 557 | $share_atts['share_email_icon'] = "<img src='{$share_email_custom_icon}' alt='{$alt_text}'/>"; |
| 558 | } else { |
| 559 | $share_atts['share_email_icon'] = ''; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | if ( $share_whatsapp_enabled ) { |
| 564 | $share_whatsapp_icon = get_option( 'yith_wcwl_wa_button_icon', 'fa-whatsapp' ); |
| 565 | $share_whatsapp_custom_icon = get_option( 'yith_wcwl_wa_button_custom_icon' ); |
| 566 | $share_whatsapp_url = ''; |
| 567 | |
| 568 | if ( wp_is_mobile() ) { |
| 569 | $share_whatsapp_url = 'whatsapp://send?text=' . $share_link_title . ' - ' . urlencode( $share_link_url ); |
| 570 | } else { |
| 571 | $share_whatsapp_url = 'https://web.whatsapp.com/send?text=' . $share_link_title . ' - ' . urlencode( $share_link_url ); |
| 572 | } |
| 573 | |
| 574 | $share_atts['share_whatsapp_url'] = $share_whatsapp_url; |
| 575 | |
| 576 | if ( ! in_array( $share_whatsapp_icon, array( 'none', 'custom' ), true ) ) { |
| 577 | $share_atts['share_whatsapp_icon'] = "<i class='fa {$share_whatsapp_icon}'></i>"; |
| 578 | } elseif ( 'custom' === $share_whatsapp_icon && $share_whatsapp_custom_icon ) { |
| 579 | $alt_text = __( 'Share on WhatsApp', 'yith-woocommerce-wishlist' ); |
| 580 | $share_atts['share_whatsapp_icon'] = "<img src='{$share_whatsapp_custom_icon}' alt='{$alt_text}'/>"; |
| 581 | } else { |
| 582 | $share_atts['share_whatsapp_icon'] = ''; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | $additional_params['share_enabled'] = true; |
| 587 | $additional_params['share_atts'] = $share_atts; |
| 588 | } |
| 589 | // phpcs:enable WordPress.PHP.DiscouragedPHPFunctions.urlencode_urlencode |
| 590 | } |
| 591 | |
| 592 | // filter params. |
| 593 | |
| 594 | /** |
| 595 | * APPLY_FILTERS: yith_wcwl_wishlist_params |
| 596 | * |
| 597 | * Filter the array with the paramters in the wishlist page. |
| 598 | * |
| 599 | * @param array $additional_params Wishlist parameters |
| 600 | * @param string $action Action |
| 601 | * @param array $action_params Action parameters |
| 602 | * @param string $pagination Use pagination or not |
| 603 | * @param int $per_page Number of items per page |
| 604 | * @param array $atts Array of attributes |
| 605 | * |
| 606 | * @return array |
| 607 | */ |
| 608 | $additional_params = apply_filters( 'yith_wcwl_wishlist_params', $additional_params, $action, $action_params, $pagination, $per_page, $atts ); |
| 609 | |
| 610 | $atts = array_merge( |
| 611 | $atts, |
| 612 | $additional_params |
| 613 | ); |
| 614 | |
| 615 | $atts['fragment_options'] = YITH_WCWL_Frontend()->format_fragment_options( $atts, 'wishlist' ); |
| 616 | |
| 617 | // apply filters for add to cart buttons. |
| 618 | YITH_WCWL_Frontend()->alter_add_to_cart_button(); |
| 619 | |
| 620 | // sets that we're in the wishlist template. |
| 621 | $yith_wcwl_is_wishlist = true; |
| 622 | |
| 623 | $template = yith_wcwl_get_template( 'wishlist.php', $atts, true ); |
| 624 | |
| 625 | // we're not in wishlist template anymore. |
| 626 | $yith_wcwl_is_wishlist = false; |
| 627 | $yith_wcwl_wishlist_token = null; |
| 628 | |
| 629 | // remove filters for add to cart buttons. |
| 630 | YITH_WCWL_Frontend()->restore_add_to_cart_button(); |
| 631 | |
| 632 | // enqueue scripts. |
| 633 | YITH_WCWL_Frontend()->enqueue_scripts(); |
| 634 | |
| 635 | return apply_filters( 'yith_wcwl_wishlisth_html', $template, array(), true ); |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Return "Add to Wishlist" button. |
| 640 | * |
| 641 | * @param array $atts Array of parameters for the shortcode. |
| 642 | * @param string $content Shortcode content (usually empty). |
| 643 | * |
| 644 | * @return string Template of the shortcode. |
| 645 | * |
| 646 | * @since 1.0.0 |
| 647 | */ |
| 648 | public static function add_to_wishlist( $atts, $content = null ) { |
| 649 | global $product; |
| 650 | |
| 651 | // product object. |
| 652 | $current_product = ( isset( $atts['product_id'] ) ) ? wc_get_product( $atts['product_id'] ) : false; |
| 653 | $current_product = $current_product ? $current_product : $product; |
| 654 | |
| 655 | if ( ! $current_product || ! $current_product instanceof WC_Product ) { |
| 656 | return ''; |
| 657 | } |
| 658 | |
| 659 | $current_product_id = yit_get_product_id( $current_product ); |
| 660 | |
| 661 | // product parent. |
| 662 | $current_product_parent = $current_product->get_parent_id(); |
| 663 | |
| 664 | // labels & icons settings. |
| 665 | $label_option = get_option( 'yith_wcwl_add_to_wishlist_text' ); |
| 666 | $icon_option = get_option( 'yith_wcwl_add_to_wishlist_icon' ); |
| 667 | $custom_icon = 'none' !== $icon_option ? get_option( 'yith_wcwl_add_to_wishlist_custom_icon' ) : ''; |
| 668 | $custom_icon_alt = apply_filters( 'yith_wcwl_custom_icon_alt', '' ); |
| 669 | $custom_icon_width = apply_filters( 'yith_wcwl_custom_width', '32' ); |
| 670 | $added_icon_option = get_option( 'yith_wcwl_added_to_wishlist_icon' ); |
| 671 | $custom_added_icon = 'none' !== $added_icon_option ? get_option( 'yith_wcwl_added_to_wishlist_custom_icon' ) : ''; |
| 672 | $browse_wishlist = get_option( 'yith_wcwl_browse_wishlist_text' ); |
| 673 | $already_in_wishlist = get_option( 'yith_wcwl_already_in_wishlist_text' ); |
| 674 | $product_added = get_option( 'yith_wcwl_product_added_text' ); |
| 675 | $loop_position = get_option( 'yith_wcwl_loop_position' ); |
| 676 | |
| 677 | // button label. |
| 678 | /** |
| 679 | * APPLY_FILTERS: yith_wcwl_button_label |
| 680 | * |
| 681 | * Filter the label of the 'Add to wishlist' button. |
| 682 | * |
| 683 | * @param string $label_option Button label |
| 684 | * |
| 685 | * @return string |
| 686 | */ |
| 687 | $label = apply_filters( 'yith_wcwl_button_label', $label_option ); |
| 688 | |
| 689 | // button icon. |
| 690 | /** |
| 691 | * APPLY_FILTERS: yith_wcwl_button_icon |
| 692 | * |
| 693 | * Filter the icon of the 'Add to wishlist' button. |
| 694 | * |
| 695 | * @param string $icon Button icon |
| 696 | * |
| 697 | * @return string |
| 698 | */ |
| 699 | $icon = apply_filters( 'yith_wcwl_button_icon', 'none' !== $icon_option ? $icon_option : '' ); |
| 700 | |
| 701 | /** |
| 702 | * APPLY_FILTERS: yith_wcwl_button_added_icon |
| 703 | * |
| 704 | * Filter the added icon of the 'Add to wishlist' button. |
| 705 | * |
| 706 | * @param string $icon Button added icon |
| 707 | * |
| 708 | * @return string |
| 709 | */ |
| 710 | $added_icon = apply_filters( 'yith_wcwl_button_added_icon', 'none' !== $added_icon_option ? $added_icon_option : '' ); |
| 711 | |
| 712 | // button class. |
| 713 | $is_single = isset( $atts['is_single'] ) ? $atts['is_single'] : yith_wcwl_is_single(); |
| 714 | $use_custom_button = get_option( 'yith_wcwl_add_to_wishlist_style' ); |
| 715 | |
| 716 | /** |
| 717 | * APPLY_FILTERS: yith_wcwl_add_to_wishlist_button_classes |
| 718 | * |
| 719 | * Filter the CSS classes of the 'Add to wishlist' button. |
| 720 | * |
| 721 | * @param string $classes Button classes |
| 722 | * |
| 723 | * @return string |
| 724 | */ |
| 725 | $classes = apply_filters( 'yith_wcwl_add_to_wishlist_button_classes', in_array( $use_custom_button, array( 'button_custom', 'button_default' ), true ) ? 'add_to_wishlist single_add_to_wishlist button alt' : 'add_to_wishlist single_add_to_wishlist' ); |
| 726 | |
| 727 | // check if product is already in wishlist. |
| 728 | $exists = YITH_WCWL()->is_product_in_wishlist( $current_product_id ); |
| 729 | $added_to_wishlist_behaviour = get_option( 'yith_wcwl_after_add_to_wishlist_behaviour', 'view' ); |
| 730 | $container_classes = $exists ? 'exists' : false; |
| 731 | $found_in_list = $exists ? yith_wcwl_get_wishlist( false ) : false; |
| 732 | $found_item = $found_in_list ? $found_in_list->get_product( $current_product_id ) : false; |
| 733 | |
| 734 | $template_part = $exists && 'add' !== $added_to_wishlist_behaviour ? 'browse' : 'button'; |
| 735 | $template_part = isset( $atts['added_to_wishlist'] ) ? ( $atts['added_to_wishlist'] ? 'added' : 'browse' ) : $template_part; |
| 736 | |
| 737 | if ( $found_in_list && in_array( $template_part, array( 'browse', 'added' ), true ) && 'remove' === $added_to_wishlist_behaviour ) { |
| 738 | $template_part = 'remove'; |
| 739 | } |
| 740 | |
| 741 | if ( 'remove' === $template_part ) { |
| 742 | $classes = str_replace( array( 'single_add_to_wishlist', 'add_to_wishlist' ), '', $classes ); |
| 743 | |
| 744 | /** |
| 745 | * APPLY_FILTERS: yith_wcwl_remove_from_wishlist_label |
| 746 | * |
| 747 | * Filter the label to remove from the wishlist. |
| 748 | * |
| 749 | * @param string $label Label |
| 750 | * |
| 751 | * @return string |
| 752 | */ |
| 753 | $label = apply_filters( 'yith_wcwl_remove_from_wishlist_label', __( 'Remove from list', 'yith-woocommerce-wishlist' ) ); |
| 754 | } |
| 755 | |
| 756 | // prevent button appearance when we're in loop, over image. |
| 757 | if ( ! $is_single && 'before_image' === get_option( 'yith_wcwl_loop_position' ) ) { |
| 758 | $classes = str_replace( 'button', '', $classes ); |
| 759 | } |
| 760 | |
| 761 | $ajax_loading = 'yes' === get_option( 'yith_wcwl_ajax_enable', 'no' ); |
| 762 | |
| 763 | // get wishlist url. |
| 764 | $wishlist_url = YITH_WCWL()->get_wishlist_url(); |
| 765 | |
| 766 | // get product type. |
| 767 | $product_type = $current_product->get_type(); |
| 768 | |
| 769 | $additional_params = array( |
| 770 | 'base_url' => yith_wcwl_get_current_url(), |
| 771 | 'wishlist_url' => $wishlist_url, |
| 772 | 'in_default_wishlist' => $exists, |
| 773 | 'exists' => $exists, |
| 774 | 'container_classes' => $container_classes, |
| 775 | 'is_single' => $is_single, |
| 776 | 'show_exists' => false, |
| 777 | 'found_in_list' => $found_in_list, |
| 778 | 'found_item' => $found_item, |
| 779 | 'product_id' => $current_product_id, |
| 780 | 'parent_product_id' => $current_product_parent ? $current_product_parent : $current_product_id, |
| 781 | 'product_type' => $product_type, |
| 782 | 'label' => $label, |
| 783 | 'show_view' => yith_wcwl_is_single(), |
| 784 | /** |
| 785 | * APPLY_FILTERS: yith_wcwl_browse_wishlist_label |
| 786 | * |
| 787 | * Filter the label to browse the wishlist. |
| 788 | * |
| 789 | * @param string $browse_wishlist Browse wishlist text |
| 790 | * |
| 791 | * @return string |
| 792 | */ |
| 793 | 'browse_wishlist_text' => apply_filters( 'yith_wcwl_browse_wishlist_label', $browse_wishlist ), |
| 794 | /** |
| 795 | * APPLY_FILTERS: yith_wcwl_product_already_in_wishlist_text_button |
| 796 | * |
| 797 | * Filter the text when the product is already in the wishlist. |
| 798 | * |
| 799 | * @param string $already_in_wishlist 'Already in wishlist' text |
| 800 | * |
| 801 | * @return string |
| 802 | */ |
| 803 | 'already_in_wishslist_text' => apply_filters( 'yith_wcwl_product_already_in_wishlist_text_button', $already_in_wishlist ), |
| 804 | /** |
| 805 | * APPLY_FILTERS: yith_wcwl_product_added_to_wishlist_message_button |
| 806 | * |
| 807 | * Filter the text when the product has been added to the wishlist. |
| 808 | * |
| 809 | * @param string $product_added 'Product added to the wishlist' text |
| 810 | * |
| 811 | * @return string |
| 812 | */ |
| 813 | 'product_added_text' => apply_filters( 'yith_wcwl_product_added_to_wishlist_message_button', $product_added ), |
| 814 | 'icon' => $icon, |
| 815 | 'heading_icon' => $icon, |
| 816 | 'link_classes' => $classes, |
| 817 | 'available_multi_wishlist' => false, |
| 818 | 'disable_wishlist' => false, |
| 819 | 'show_count' => false, |
| 820 | 'ajax_loading' => $ajax_loading, |
| 821 | 'loop_position' => $loop_position, |
| 822 | 'template_part' => $template_part, |
| 823 | ); |
| 824 | // let third party developer filter options. |
| 825 | |
| 826 | /** |
| 827 | * APPLY_FILTERS: yith_wcwl_add_to_wishlist_params |
| 828 | * |
| 829 | * Filter the array with the paramters for the 'Add to wishlist' action. |
| 830 | * |
| 831 | * @param array $additional_params Wishlist parameters |
| 832 | * @param array $atts Array of attributes |
| 833 | * |
| 834 | * @return array |
| 835 | */ |
| 836 | $additional_params = apply_filters( 'yith_wcwl_add_to_wishlist_params', $additional_params, $atts ); |
| 837 | |
| 838 | $atts = shortcode_atts( |
| 839 | $additional_params, |
| 840 | $atts |
| 841 | ); |
| 842 | |
| 843 | // add no-icon class when item is shown without icon. |
| 844 | if ( $is_single && empty( $atts['icon'] ) ) { |
| 845 | $atts['container_classes'] .= ' no-icon'; |
| 846 | } |
| 847 | |
| 848 | // add no-icon class when item is shown without icon. |
| 849 | if ( $exists && $atts['show_count'] ) { |
| 850 | $atts['container_classes'] .= ' with-count'; |
| 851 | } |
| 852 | |
| 853 | // set icon when missing, when on top of image (icon only, icon required). |
| 854 | if ( ! $is_single && 'before_image' === get_option( 'yith_wcwl_loop_position' ) && ( ! $atts['icon'] || 'custom' === $atts['icon'] ) ) { |
| 855 | if ( ! $atts['icon'] ) { |
| 856 | $atts['icon'] = 'fa-heart-o'; |
| 857 | } elseif ( 'custom' === $atts['icon'] && ! $custom_icon && ! $custom_added_icon ) { |
| 858 | $atts['icon'] = 'fa-heart-o'; |
| 859 | } |
| 860 | } |
| 861 | |
| 862 | // change icon when item exists in wishlist. |
| 863 | if ( $atts['exists'] ) { |
| 864 | if ( $added_icon && ( 'custom' !== $added_icon || $custom_added_icon || $custom_icon ) ) { |
| 865 | $atts['icon'] = $added_icon; |
| 866 | } elseif ( strpos( $atts['icon'], '-o' ) !== false ) { |
| 867 | $atts['icon'] = str_replace( '-o', '', $atts['icon'] ); |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | if ( 'custom' === $atts['icon'] && $atts['exists'] && $custom_added_icon ) { |
| 872 | $icon_html = '<img class="yith-wcwl-icon" src="' . esc_url( $custom_added_icon ) . '" alt="' . esc_attr( $custom_icon_alt ) . '" width="' . esc_attr( $custom_icon_width ) . '" />'; |
| 873 | $heading_icon_html = ! empty( $custom_icon ) ? '<img class="yith-wcwl-icon" src="' . esc_url( $custom_icon ) . '" alt="' . esc_attr( $custom_icon_alt ) . '" width="' . esc_attr( $custom_icon_width ) . '" />' : ''; |
| 874 | } elseif ( 'custom' === $atts['icon'] && $custom_icon ) { |
| 875 | $icon_html = '<img class="yith-wcwl-icon" src="' . esc_url( $custom_icon ) . '" alt="' . esc_attr( $custom_icon_alt ) . '" width="' . esc_attr( $custom_icon_width ) . '" />'; |
| 876 | $heading_icon_html = $icon_html; |
| 877 | } elseif ( 'custom' !== $atts['icon'] ) { |
| 878 | $icon_html = ! empty( $atts['icon'] ) ? '<i class="yith-wcwl-icon fa ' . $atts['icon'] . '"></i>' : ''; |
| 879 | $heading_icon_html = ! empty( $atts['heading_icon'] ) ? '<i class="yith-wcwl-icon fa ' . $atts['heading_icon'] . '"></i>' : ''; |
| 880 | } else { |
| 881 | $icon_html = ''; |
| 882 | $heading_icon_html = ''; |
| 883 | } |
| 884 | |
| 885 | // set fragment options. |
| 886 | $atts['fragment_options'] = YITH_WCWL_Frontend()->format_fragment_options( $atts, 'add_to_wishlist' ); |
| 887 | |
| 888 | /** |
| 889 | * APPLY_FILTERS: yith_wcwl_add_to_wishlist_icon_html |
| 890 | * |
| 891 | * Filter the HTML of the icon for the 'Add to wishlist'. |
| 892 | * |
| 893 | * @param string $icon_html HTML icon |
| 894 | * @param array $atts Array of attributes |
| 895 | * |
| 896 | * @return string |
| 897 | */ |
| 898 | $atts['icon'] = apply_filters( 'yith_wcwl_add_to_wishlist_icon_html', $icon_html, $atts ); |
| 899 | |
| 900 | /** |
| 901 | * APPLY_FILTERS: yith_wcwl_add_to_wishlist_heading_icon_html |
| 902 | * |
| 903 | * Filter the HTML of the heading icon for the 'Add to wishlist'. |
| 904 | * |
| 905 | * @param string $icon_html HTML icon |
| 906 | * @param array $atts Array of attributes |
| 907 | * |
| 908 | * @return string |
| 909 | */ |
| 910 | $atts['heading_icon'] = apply_filters( 'yith_wcwl_add_to_wishlist_heading_icon_html', $heading_icon_html, $atts ); |
| 911 | |
| 912 | $template = yith_wcwl_get_template( 'add-to-wishlist.php', $atts, true ); |
| 913 | |
| 914 | // enqueue scripts. |
| 915 | YITH_WCWL_Frontend()->enqueue_scripts(); |
| 916 | |
| 917 | /** |
| 918 | * APPLY_FILTERS: yith_wcwl_add_to_wishlisth_button_html |
| 919 | * |
| 920 | * Filter the HTML of the 'Add to wishlist' button. |
| 921 | * |
| 922 | * @param string $template Button HTML |
| 923 | * @param string $wishlist_url Wishlist URL |
| 924 | * @param string $product_type Product type |
| 925 | * @param bool $exists Whether the product is already in the wishlist |
| 926 | * @param array $atts Array of attributes |
| 927 | * |
| 928 | * @return string |
| 929 | */ |
| 930 | return apply_filters( 'yith_wcwl_add_to_wishlisth_button_html', $template, $wishlist_url, $product_type, $exists, $atts ); |
| 931 | } |
| 932 | |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | YITH_WCWL_Shortcode::init(); |
| 937 |