• Resolved monster-it

    (@monster-it)


    Hi All, Been trying to add two endpoints on the a site for GDPR. However I can only get one working.
    1. close account
    2. request return

    Here’s my functions.php code:

    function my_custom_endpoints() {
        add_rewrite_endpoint( 'close-account', EP_ROOT | EP_PAGES );
    	add_rewrite_endpoint( 'request-return', EP_ROOT | EP_PAGES );
    }
    
    add_action( 'init', 'my_custom_endpoints' );
    
    function my_custom_query_vars( $vars ) {
        $vars[] = 'close-account';
    	$vars[] = 'request-return';
    
        return $vars;
    }
    
    add_filter( 'query_vars', 'my_custom_query_vars', 0 );
    
    function my_custom_flush_rewrite_rules() {
        flush_rewrite_rules();
    }
    
    add_action( 'wp_loaded', 'my_custom_flush_rewrite_rules' );
    function my_custom_endpoint_content() {
        include 'woocommerce/myaccount/close-account.php';
    	include 'woocommerce/myaccount/request-return.php';
    }
    
    add_action( 'woocommerce_account_close-account_endpoint', 'my_custom_endpoint_content' );

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter monster-it

    (@monster-it)

    Found the solution:

    function my_custom_endpoints() {
        add_rewrite_endpoint( 'close-account', EP_ROOT | EP_PAGES );
        add_rewrite_endpoint( 'request-return', EP_ROOT | EP_PAGES ); 
    }
    add_action( 'init', 'my_custom_endpoints' );
    
    function my_custom_query_vars( $vars ) {
        $vars[]= 'close-account';
        $vars[] = 'request-return';
        return $vars;
    }
    
    add_filter( 'query_vars', 'my_custom_query_vars', 0 );
    
    function my_custom_my_account_menu_items( $items ) {
        $items = array(
            'dashboard'         => __( 'Dashboard', 'woocommerce' ),
            'orders'            => __( 'Orders', 'woocommerce' ),
            //'downloads'       => __( 'Downloads', 'woocommerce' ),
            'edit-account'      => __( 'Edit Accounts', 'woocommerce' ),
            'edit-address'    => __( 'Addresses', 'woocommerce' ),
            'payment-methods' => __( 'Payment Methods', 'woocommerce' ),
            'request-return'      => __( 'Request Return', 'woocommerce' ),
            'close-account'     => __( 'Close Account', 'woocommerce' ),
    		'customer-logout'   => __( 'Logout', 'woocommerce' ),
        );
    
        return $items;
    }
    
    add_filter( 'woocommerce_account_menu_items', 'my_custom_my_account_menu_items' );
    
    function request_return_endpoint_content() {
        include 'woocommerce/myaccount/request-return.php';   
    }
    add_action( 'woocommerce_account_request-return_endpoint', 'request_return_endpoint_content' );
    
    function close_account_endpoint_content() {
        include 'woocommerce/myaccount/close-account.php';  
    }
    add_action( 'woocommerce_account_close-account_endpoint', 'close_account_endpoint_content' );
    
    function my_custom_flush_rewrite_rules() {
        flush_rewrite_rules();
    }
    add_action( 'after_switch_theme', 'my_custom_flush_rewrite_rules' );
Viewing 1 replies (of 1 total)
  • The topic ‘Adding two endpoints’ is closed to new replies.