Viewing 2 replies - 1 through 2 (of 2 total)
  • Pankaj

    (@pankajtechilagmailcom)

    Hello,
    I am also having the same requirement, Can anyone give solution that how we can add the link of add to wishlist btn

    Thanks

    I have a custom post type of name food_menu. Each of my food_menu single posts are related to a WooCommerce product through a custom field that gets the product id. I’m also trying to display the wishlist button outside woocommerce pages with no success.

    With the function bellow I’m able to customize the whole button states and echo it on woocommerce pages, but if I try to echo the function anywhere else I got errors.

        /* WishList Button on single post type page */
        function mytheme_wishlist_button_food_menu() {
    
        global $product;
    
        // Gets the product id attached to the post of type food_menu, which is set in the CMB2 custom field 'related_product"
        $product_related = get_post_meta( get_the_ID(), '_mytheme_related_product', true );
    
        $product->id = $product_related; 
    
        if ( class_exists( 'YITH_WCWL_UI' ) )  {
            $url = YITH_WCWL()->get_wishlist_url();
            $product_type = $product->product_type;
            $default_wishlists = is_user_logged_in() ? YITH_WCWL()->get_wishlists( array( 'is_default' => true ) ) : false;
    
            if( ! empty( $default_wishlists ) ){
                $default_wishlist = $default_wishlists[0]['ID'];
            }
            else{
                $default_wishlist = false;
            }
    
            $exists = YITH_WCWL()->is_product_in_wishlist( $product->id, $default_wishlist );
    
            $classes = get_option( 'yith_wcwl_use_button' ) == 'yes' ? 'class="add_to_wishlist single_add_to_wishlist btn btn-default btn-outline"' : 'class="add_to_wishlist single_add_to_wishlist btn btn-default btn-default"';
    
            $html  = '<div class="yith-wcwl-add-to-wishlist add-to-wishlist-'.$product->id.'">';
            $html .= '<div class="yith-wcwl-add-button';  // the class attribute is closed in the next row
    
            $html .= $exists ? ' hide" style="display:none;"' : ' show"';
            // Not added button
            $html .= '<a>get_addtowishlist_url()) . '" data-product-id="' . $product->id . '" data-product-type="' . $product_type . '" ' . $classes . ' class="btn btn-default btn-outline" data-toggle="button" >';
            $html .= '<span class="text">'.__( "Favorite", 'mytheme' ).'</span>';
            $html .= '<i class="icon wb-heart-outline text" aria-hidden="true"></i>';
            $html .= '</a>';
            $html .= '</div>';
    
            // Added button
            $html .= '<div class="yith-wcwl-wishlistaddedbrowse hide" style="display:none;">';
            $html .= '<a href="' . esc_url($url) . '">id . '" data-product-type="' . $product->id . '" ' . $classes . ' class="btn btn-default btn-outline" data-toggle="button" >';
            $html .= '<i class="icon wb-heart text-active text-danger" aria-hidden="true"></i>';
            $html .= '<span class="text-active">'.__( "Add to Wishlist", 'mytheme' ).'</span>';
            $html .= '</a>';
            $html .= '</div>';
    
            // Already Added button
            $html .= '<div class="yith-wcwl-wishlistexistsbrowse ' . ( $exists ? 'show' : 'hide' ) . '" style="display:' . ( $exists ? 'block' : 'none' ) . '"><a href="' . esc_url($url) . '"><i class="icon icon_heart icon-btn icon-filled"></i> <span class="text">'.__( "Already on Wishlist", 'mytheme' ).'</span></a></div>';
            $html .= '<div style="clear:both"></div><div class="yith-wcwl-wishlistaddresponse"></div>';
    
            $html .= '</div>';
    
            return $html;
    
            }
    
        }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Place Add To Wishlist button in another template via PHP?’ is closed to new replies.