• I want to add an endpoint to the dashboard menu.
    I want to use this section as advertising tools such as placing banners.
    I added the following line to the class-yith-wcaf-endpoints.php file.

    'banners' => _x( 'Banners', '[GLOBAL] Endpoint title', 'yith-woocommerce-affiliates' ),

    I also saved the Permalink Settings again to fix the 404 error.
    With this, the banners item was added to the dashboard menu. Then I created a file called dashboard-banners.php in the templates/shortcodes path and put the following code in it.

    <?php
    /**
      * Affiliate Banners
      *
      * @author YITH
      * @package YITH\Affiliates\Templates
      * @version 2.0.0
      */
    
    /**
      * Template variables:
      *
      * @var $affiliate YITH_WCAF_Affiliate
      * @var $generated_url string
      * @var $original_url string
      * @var $share_enabled bool
      * @var $atts array
      * @var $share_atts array
      */
    
    if ( ! defined( 'YITH_WCAF' ) ) {
         exit;
    } // Exit if accessed directly
    ?>
    
    <?php
    do_action( 'yith_wcaf_before_dashboard_section', 'banners', $atts );
    ?>
    <div>
         <h1>Welcome to the Banners endpoint!</h1>
    </div>
    <?php
    do_action( 'yith_wcaf_after_dashboard_section', 'banners', $atts );

    Now I want the custom content that I put in the dashboard-banners.php file to be displayed at the endpoint of the banners.
    Please advise what other file should I add or edit.
    Of course, adding the banner section can be a good suggestion for the developers of this plugin.
    I appreciate any help and guidance.
    Thank You

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there,
    Thank you for contacting us!

    To register the new endpoint you should use the following filter:

    yith_wcaf_available_endpoints

    If you want to add a new entry or a custom page link in the affiliate dashboard menu, you need to use a code like the following one, by adding it to the functions.php file of your active theme:

    if ( defined( 'YITH_WCAF' ) ) {
       if ( ! function_exists( 'yith_wcaf_available_endpoints' ) ) {
          function yith_wcaf_available_endpoints( $endpoints ) {
             $endpoints['your_custom_link'] = 'Your Custom Link';
    
             return $endpoints;
          }
    
          add_filter( 'yith_wcaf_available_endpoints', 'yith_wcaf_available_endpoints' );
       }
    
       if ( ! function_exists( 'yith_wcaf_change_settings_page_url' ) ) {
          function yith_wcaf_change_settings_page_url( $url, $endpoint ) {
             if ( 'your_custom_link' === $endpoint ) {
                $url = get_the_permalink( get_page_by_path( 'your-custom-page-slug' ) );
             }
    
             return $url;
          }
          add_filter( 'yith_wcaf_get_endpoint_url', 'yith_wcaf_change_settings_page_url', 10, 2 );
       }
    }

    In this code, you will need to enter the details of the custom links you want to add. First of all, you need to update this line:

    <span style="background-color: rgb(248, 249, 249); color: rgb(104, 115, 125); font-family: Consolas, "Liberation Mono", Menlo, "Bitstream Vera Sans Mono", Courier, monospace; font-size: 12.025px;">$endpoints['your_custom_link'] = 'Your Custom Link';</span>

    to set the new endpoint to the affiliate dashboard, editing the endpoint ID and the text that will be visible to your users.

    After adding the endpoint, you will need to edit this section to make the URL of the custom link valid:

    if ( 'your_custom_link' === $endpoint ) {
        $url = get_the_permalink( get_page_by_path( 'your-custom-page-slug' ) );
    }

    where you have to change the?your_custom_link?with the endpoint ID previously added:

    'your_custom_link' === $endpoint 

    And finally, change the slug of the custom page you want to add here:

    get_page_by_path( 'your-custom-page-slug' ) );

    This is the correct way to do what you want avoiding customizing any plugin files, so you can continue updating the plugin normally.
    Please, give it a try and let us know.

    Have a nice day!

    Thread Starter matinz

    (@matinz)

    Thank you for your answer and guidance
    However, the provided code only adds a custom link to the affiliate dashboard menu and sets its URL to a custom page. It does not create a new endpoint or display additional content in the affiliate dashboard.
    But my request for help is an endpoint. In fact, something like other endpoints.
    Displaying custom content in a separate page is different from displaying content in endpoint.

    Is there any way or help so that I can get the answer to my question?

    • This reply was modified 1 year, 10 months ago by matinz.

    Hi there,

    The above reply is the only way to do what you want to do without needing to change the plugin files. We always try to work this way so you can continue updating the plugin.
    You need to create a custom page and then use the URL of that page.

    Otherwise, you need to customize the plugin.

    Have a nice day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add custom endpoints and content’ is closed to new replies.