• Resolved Ninos

    (@ninos-ego)


    The yith_wcwl_add_to_wishlist shordcode (YITH_WCWL_Shortcode::add_to_wishlist()) don’t use the attributes you send with. It’s because you’re using the shortcode_atts() in a wrong way. Remove it from the top of the method and replace

    $atts = array_merge(
        $atts,
        $additional_params
    );

    with
    $atts = shortcode_atts( $additional_params, $atts );

    Here’s the complete code:

    /**
             * Return "Add to Wishlist" button.
             *
             * @since 1.0.0
             */
            public static function add_to_wishlist( $atts, $content = null ) {
                global $product;
    
                $template_part = 'button';
    
                $label_option = get_option( 'yith_wcwl_add_to_wishlist_text' );
                $icon_option = get_option( 'yith_wcwl_add_to_wishlist_icon' ) != 'none' ? '<i class="' . get_option( 'yith_wcwl_add_to_wishlist_icon' ) . '"></i>' : '';
    
                $localize_label = function_exists( 'icl_translate' ) ? icl_translate( 'Plugins', 'plugin_yit_wishlist_button', $label_option ) : $label_option;
    
                $label = apply_filters( 'yith_wcwl_button_label', $localize_label );
                $icon = apply_filters( 'yith_wcwl_button_icon', $icon_option );
    
                $classes = apply_filters( 'yith_wcwl_add_to_wishlist_button_classes', get_option( 'yith_wcwl_use_button' ) == 'yes' ? 'add_to_wishlist single_add_to_wishlist button alt' : 'add_to_wishlist' );
    
                $wishlist_url = YITH_WCWL()->get_wishlist_url();
                $exists = YITH_WCWL()->is_product_in_wishlist( $product->id );
                $product_type = $product->product_type;
    
                $additional_params = array(
                    'wishlist_url' => $wishlist_url,
                    'exists' => $exists,
                    'product_id' => $product->id,
                    'product_type' => $product_type,
                    'label' => $label,
                    'icon' => $icon,
                    'link_classes' => $classes,
                    'available_multi_wishlist' => false,
                );
    
                $additional_params = apply_filters( 'yith_wcwl_add_to_wishlist_params', $additional_params );
                $additional_params['template_part'] = isset( $additional_params['template_part'] ) ? $additional_params['template_part'] : $template_part;
    
                $atts = shortcode_atts( $additional_params, $atts );
    
                // adds attributes list to params to extract in template, so it can be passed through a new get_template()
                $atts['atts'] = $atts;
    
                $template = yith_wcwl_get_template( 'add-to-wishlist.php', $atts, true );
    
                return apply_filters( 'yith_wcwl_add_to_wishlisth_button_html', $template, $wishlist_url, $product_type, $exists );
            }

    Thanks 🙂

    https://wordpress.org/plugins/yith-woocommerce-wishlist/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi again, Ninos!

    This is because the shortcode [yith_wcwl_add_to_wishlist] was not intended to receive any attribute; the $additional_params array is a list of variables needed in the template, calculated by the script and not editable by users.

    This is a design choise.

    In wich case do you have to pass atts to the shortcode, or edit additional_info array? Maybe yith_wcwl_add_to_wishlist_params filter is best suited for your goals 🙂

    Thread Starter Ninos

    (@ninos-ego)

    Hey there, thanks for your response. I want to do something like that:

    <?php if( class_exists('YITH_WCWL') ) : ?>
    	<?php echo YITH_WCWL_Shortcode::add_to_wishlist( array('template_part' => 'another_one') ); ?>
    <?php endif; ?>

    It’s planned to support your plugin by default in one of our themes we want to sell next week and the filter would not solve my problem. In my example I want to use two different template files to show your wishlist button. One for the single page, one for the products content. I cannot use the function is_product() (also not in the filter) for checking, because I also have some content products in the single product page (related products). So the template selector there would not work. I could do a query check (is_main_query()), but it’s very bad for the performance for such a little think.

    It would be very great if you could at least add support for one of the params, for example template_part 🙂

    Plugin Author YITHEMES

    (@yithemes)

    Hi Ninos, for this and previous requests, check version 2.0.3

    Have a nice day, and good luck with your work 🙂

    Thread Starter Ninos

    (@ninos-ego)

    Omg love you guys, thanks!! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘yith_wcwl_add_to_wishlist shortcode don't use the params’ is closed to new replies.