ホームページ  >  に質問  >  本文

WooCommerce カスタム タブのコンテンツ表示の問題を解決する方法

以下のコードを使用して、WooCommerce の [マイ アカウント] タブに複数のタブを追加しましたが、問題が 1 つだけあります。タブごとにカスタム コンテンツを表示できないのですが、何か方法はありますか?

ああああ

P粉986937457P粉986937457381日前459

全員に返信(1)返信します

  • P粉026665919

    P粉0266659192023-09-07 16:02:04

    $endpoints = array(
        'fistkey' => 'firstlabel',
        'secondkey' => 'secondlabel'
    );
    
    function pa_custom_endpoint_keys() {
    
        $endpoints = array(
            'fistkey' => 'firstlabel',
            'secondkey' => 'secondlabel'
        );
        foreach ($endpoints as $key => $value) {
            $endpointsdata[$key] = $value;
        }
        return $endpointsdata;
    }
    
    add_action('init', 'pa_custom_endpoint');
    
    function pa_custom_endpoint() {
        $endpoints = array(
            'fistkey' => 'firstlabel',
            'secondkey' => 'secondlabel'
        );
        foreach ($endpoints as $endpointkey => $endpointlable) {
            add_rewrite_endpoint($endpointkey, EP_ROOT | EP_PAGES);
            if (!get_option('plugin_permalinks_flushed')) {
    
                flush_rewrite_rules(false);
                update_option('plugin_permalinks_flushed', 1);
            }
        }
    }
    
    add_filter('query_vars', 'pa_custom_endpoint_query_vars', 0);
    
    function pa_custom_endpoint_query_vars($vars) {
        $endpoints = array(
            'fistkey' => 'firstlabel',
            'secondkey' => 'secondlabel'
        );
        foreach ($endpoints as $endpointkey => $endpointlable) {
            $vars[] = $endpointkey;
        }
        return $vars;
    }
    
    add_filter('woocommerce_account_menu_items', 'pa_custom_endpoint_link_my_account');
    
    function pa_custom_endpoint_link_my_account($items) {
        $endpoints = array(
            'fistkey' => 'firstlabel',
            'secondkey' => 'secondlabel'
        );
        foreach ($endpoints as $endpointkey => $endpointlable) {
            $items[$endpointkey] = $endpointlable;
        }
        return $items;
    }
    
    function mine($endpointlable) {//i just need to make this function like this $mine(){}
        global $wp;
        $request = explode('/', $wp->request);
        $myaccount_current_endpoint = end($request);
        var_dump($myaccount_current_endpoint);
        exit;
        //echo do_shortcode(' /* your shortcode here  ');
    }
    
    foreach ($endpoints as $endpointkey => $endpointlable) {
    
        add_action('woocommerce_account_' . $endpointkey . '_endpoint', 'mine');
    }

    返事
    0
  • キャンセル返事