Façons de résoudre les problèmes d'affichage du contenu des onglets personnalisés WooCommerce
P粉986937457
P粉986937457 2023-09-06 19:45:22
0
1
515

À l'aide du code ci-dessous, j'ai ajouté plusieurs onglets à l'onglet Mon compte de WooCommerce, avec un seul problème : je ne peux pas afficher de contenu personnalisé pour chaque onglet, y a-t-il un moyen ?

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

P粉986937457
P粉986937457

répondre à tous(1)
P粉026665919
$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');
}
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!