Please submit a private ticket if you need to share sensitive information, such as license details and admin credentials.

Okay
  Public Ticket #3850156
Presale inquiry - plugin for my-account customisation needed
Open

Comments

  •  2
    Ellisabeth started the conversation

    Hello, One of my customers wants to add 4 - 6 products to an extra tab in the my account area. I know Yith makes a plugin to customize the my account area, but on this site a few of your plugins are already in use and I'd prefer to stick with WPclever. Do you offer something like this? I couldn't find it, but maybe I overlooked it.

    Thank you.

  •  1,404
    Dustin replied

    Hi Ellisabeth,

    Please tell me more about your requirements. Are those products predefined for all users, or how are they determined?

    I can write a snippet to do that instead of using a plugin.

    Best regards,
    Dustin

  •  2
    Ellisabeth replied

    Hello Dustin, I didn't get a notification by email that you had replied that's why I am respondingly late, sorry. Here are the requirements for the adjustment of the 'my account' area.

    1. An extra tab where some products can be shown for the user to buy.

    2. The products are in a specific category (name = CooLe stuff, slug = praatplaat).

    3. 6 of the 7 products have a tag assigned 'only for license owners/alleen voor licentiehouders' 

    4. because only users with the user role 'subscriber' or  'admin'(those are license owners) must be able to see and buy these products.

    I hope it will work and thanks, Elisabeth

  •  1,404
    Dustin replied

    Please add the custom code below. (How to add custom code? ↗):

    add_filter( 'woocommerce_account_menu_items', function ( $items ) {
    	if ( isset( $items['customer-logout'] ) ) {
    		$logout = $items['customer-logout'];
    		unset( $items['customer-logout'] );
    	} else {
    		$logout = '';
    	}
    
    	if ( ! isset( $items['suggestion'] ) ) {
    		$items['suggestion'] = 'Suggestion Products';
    	}
    
    	if ( $logout ) {
    		$items['customer-logout'] = $logout;
    	}
    
    	return $items;
    }, 99 );
    
    add_action( 'init', function () {
    	add_rewrite_endpoint( 'suggestion', EP_PAGES );
    } );
    
    add_action( 'wp_head', function () {
    	?>
        <style>
            .wpc-suggestion-products .image img {
                width: 80px;
                height: auto;
            }
        </style>
    	<?php
    } );
    
    add_action( 'woocommerce_account_suggestion_endpoint', function () {
    	$args = [
    		'status'    => [ 'publish' ],
    		'limit'     => 100,
    		'tax_query' => [
    			[
    				'taxonomy' => 'product_tag',
    				'field'    => 'slug',
    				'terms'    => [ 'tag1', 'tag2' ],
    				'operator' => 'IN',
    			]
    		]
    	];
    
    	$suggestion_products = wc_get_products( $args );
    
    	if ( is_array( $suggestion_products ) && ! empty( $suggestion_products ) ) {
    		echo '<table class="wpc-suggestion-products"><thead><tr><th>Image</th><th>Name</th><th>Action</th></tr></thead>';
    
    		foreach ( $suggestion_products as $suggestion_product ) {
    			echo '<tr class="wpc-suggestion-product">';
    			echo '<td class="image">' . $suggestion_product->get_image() . '</td>';
    			echo '<td class="info"><div class="name"><a href="' . esc_url( $suggestion_product->get_permalink() ) . '">' . $suggestion_product->get_name() . '</a></div><div class="price">' . $suggestion_product->get_price_html() . '</div> </td>';
    			echo '<td class="action">' . do_shortcode( '[add_to_cart style="" show_price="false" id="' . esc_attr( $suggestion_product->get_id() ) . '"]' ) . '</td>';
    			echo '</tr>';
    		}
    
    		echo '</table>';
    	}
    }, 99 );

    And the result will be like this:

    2046114770.png

    You can change 'tag1' and 'tag2' in the above snippet to another.

    Best regards,
    Dustin