在网站上,用户填写一张表格,在网站上创建他们的页面以显示信息.在My Account页面中,我创建了一个链接,将登录用户带到WordPress仪表板,他们可以在那里编辑此页面.
// Add Store link WooCommerce Navigation
add_filter ( 'woocommerce_account_menu_items', 'one_more_link' );
function one_more_link( $menu_links ){
$new = array( 'stall-page' => 'Edit Stall Information' );
$menu_links = array_slice( $menu_links, 0, 1, true )
+ $new
+ array_slice( $menu_links, 1, NULL, true );
return $menu_links;
}
// hook the URL
add_filter( 'woocommerce_get_endpoint_url', 'hook_endpoint', 10, 4 );
function hook_endpoint( $url, $endpoint, $value, $permalink ){
if( 'stall-page' === $endpoint ) {
$url = 'https://websitename.com/wp-admin/edit.php?post_type=stallholders';
}
return $url;
}
我想更进一步,直接链接到他们需要编辑的页面.
我一直在做实验,并取得了这样的成果:
// hook the URL
add_filter( 'woocommerce_get_endpoint_url', 'hook_endpoint', 10, 4 );
function hook_endpoint( $url, $endpoint, $value, $permalink ){
$current_user = wp_get_current_user();
$post_id = $current_user->post_ID;
if( 'stall-page' === $endpoint ) {
$url = 'https://websitename.com/wp-admin/post.php?post=' . $post_id . '&action=edit';
}
return $url;
}
但这是链接到用户ID而不是他们的自定义帖子类型页面吗?