使用下面的代码,我添加了多个选项卡到WooCommerce我的帐户选项卡与端点,只是唯一的问题是:我不能显示每个端点的自定义选项卡内容,请无论如何都有吗?

function pa_custom_endpoint_keys() {
    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate();
    $pao  = $wpdb->prefix . 'pao';
    $results=$wpdb->get_results("select * from $pao");
        $endpointsdata =array();
        foreach($results as $row){
        $endpointsdata[$row->pao_name] = $row->pao_value;
        }
        return $endpointsdata;
}
add_action( 'init', 'pa_custom_endpoint' );
function pa_custom_endpoint() {
    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
    add_rewrite_endpoint( $endpointkey, EP_ROOT | EP_PAGES );
    }
}
add_filter( 'query_vars', 'pa_custom_endpoint_query_vars', 0 );
function pa_custom_endpoint_query_vars( $vars ) {
    foreach(pa_custom_endpoint_keys() 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 ) {
    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
    $items[$endpointkey] = $endpointlable;
    }
    return $items;
}
        function mine(){//i just need to make this function like this $mine(){}
                   echo do_shortcode( ' /* your shortcode here  ' );
        }
                    foreach(pa_custom_endpoint_keys() as $endpointkey=>$endpointlable){
                
                    add_action( 'woocommerce_account_' . $endpointkey . '_endpoint', 'mine' );
            }

推荐答案

$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');
}

enter image description here

Php相关问答推荐

如何在Livewire中验证多个 Select 字段

为什么注册SIGHUP的处理程序函数会阻止在PHP CLI中等待输入时点击X关闭Xterm窗口?""

管理员订单列表中的自定义列与WooCommerce 8.6.1一起消失

一列必须指定多个变量的Laravel查询

在函数内部获取一致的单选按钮值以更新WordPress用户数据

为什么正则表达式与得到的文本块之前得到的也行?

根据WooCommerce购物车页面中的自定义 Select 添加费用

这是在可召回的背景下吗?

PHP根据特定索引值从中删除子数组

是否使用联系人表单7 wpcf7_Feedback_Response输出答复中的html?

HTAccess重写一些URL,但将所有其他URL发送到另一个页面

Laravel Carbon DiffForHumans选项(年,月,天)

强制客户在注册时 Select WooCommerce角色

文本到语音:不考虑音高值

Shopware 6 插件:如何删除布尔配置并将其迁移到多选配置

无法在 Laravel 中实例化抽象类 ProductAbstract

基于WooCommerce中的产品变体自定义感谢页面跳转

批量作业(job)提交错误无法处理所有文档,uris 似乎正确?

同时执行odbc_execute、odbc_fetch_row和odbc_result

如果 static:: 被解析为B,为什么 PHP 会执行A的方法