从插件更改Woo自定义终结点标题

时间:2019-09-27 作者:Alex Knopp

我已经创建了一些工作正常的自定义端点。我在尝试更新端点页面标题时遇到了真正的问题,我在网上搜索了很多例子,但似乎什么都没用。

这里是我添加新菜单项的地方:

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);
这在我的帐户菜单上添加了一个“产品提交”项,很好。然后,这些是我用于添加其余端点的操作。

 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);

}
现在回调可以很好地工作,因为所有功能etc都可以在所有端点上工作。但是,无论我尝试添加什么过滤器,端点始终将“您的帐户”(从“我的帐户”更改)显示为页面标题。可能是因为我从一个自定义插件添加了这个。或者我只是在初始设置中遗漏了什么?TIA公司

1 个回复
SO网友:Alex Knopp
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;

}