0

I've created some custom endpoints which are working well. Im having real issues trying to update the endpoint page titles, Ive search a lot of examples online and nothing seems to be working.

Here is where I add the new menu item:

function knp_add_account_menu_item($items){
$user = wp_get_current_user();
if ($user->caps['supplier'] == 1 || $user->caps['administrator']) {     
    $items['product-submissions'] = 'Product Submissions';
}
return $items;  
}
add_filter('woocommerce_account_menu_items', 'knp_add_account_menu_item', 30);

This adds a "Product Submissions" item on teh my account menu, great. Then these are the actions I use for adding the remaining endpoints.

 public function start(){

    add_action('init', array($this, 'knp_supplier_endpoint'));

    //Add endpoint urls
    add_action('woocommerce_account_product-submissions_endpoint', array($this, 'knp_product_submissions_content'));
    add_action('woocommerce_account_submission-form_endpoint', array($this, 'knp_submission_form_content'));
    add_action('woocommerce_account_review_endpoint', array($this, 'knp_review_content'));
    add_action('woocommerce_account_delete_endpoint', array($this, 'knp_delete_content'));
}

public function knp_supplier_endpoint(){

    add_rewrite_endpoint('product-submissions', EP_PAGES);
    add_rewrite_endpoint('submission-form', EP_PAGES);
    add_rewrite_endpoint('review', EP_PAGES);
    add_rewrite_endpoint('delete', EP_PAGES);

}

Now the callbacks work fine as all the functionality etc is working on all of the end points. However, the endpoint always shows "Your Account" (changed from "My Account") as the page title no matter what filter I try to add. Could it be because Im adding this from a custom plugin perhaps. Or am I just missing something in my initial setup? TIA

1
  • Have you tried using the the_title filter hook to change the title?
    – Sally CJ
    Commented Oct 2, 2019 at 19:07

1 Answer 1

1
public function start(){

add_action('init', array($this, 'knp_supplier_endpoint'));

//Add endpoint urls
add_action('woocommerce_account_product-submissions_endpoint', array($this, 'knp_product_submissions_content'));
add_action('woocommerce_account_submission-form_endpoint', array($this, 'knp_submission_form_content'));
add_action('woocommerce_account_review_endpoint', array($this, 'knp_review_content'));
add_action('woocommerce_account_delete_endpoint', array($this, 'knp_delete_content'));

//Answer using this filter
add_filter( 'the_title', array($this, 'knpv_title_filter'), 10, 2);
}

public function knpv_title_filter($title, $id = null){

    global $wp_query;

    if (in_the_loop() && array_key_exists('submission-form', $wp_query->query)) {

        $title = 'Create / Edit Submission';

    } elseif (in_the_loop() && array_key_exists('product-submissions', $wp_query->query)) {

        $title = 'Product Submissions';

    } elseif (in_the_loop() && array_key_exists('review', $wp_query->query)) {

        $title = 'Submit Product For Review';

    } elseif (in_the_loop() && array_key_exists('delete', $wp_query->query)) {

        $title = 'Delete Submission';

    }

    return $title;

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.