php - WooCommerce 我的帐户仪表板:编辑帐单地址的直接链接
问题描述
当我销售虚拟产品时,我不需要 WooCommerce 送货地址字段。我已经从结帐页面中删除了它们,并且还想从“我的帐户”页面中删除它们。
在“编辑地址”选项卡下的仪表板中,用户应该被直接引导到他可以编辑帐单地址的页面。不再需要显示帐单/送货地址以及用户必须单击“编辑地址”的页面。
有没有办法做到这一点?任何帮助表示赞赏。
解决方案
您可以取消设置Address
端点并为Billing
. 例如,在您functions.php
添加以下代码。
//1
function add_d_endpoint() {
add_rewrite_endpoint( 'billing', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'add_d_endpoint' );
//2
function d_query_vars( $vars ) {
$vars[] = 'billing';
return $vars;
}
add_filter( 'query_vars', 'd_query_vars', 0 );
//3
function add_d_link_my_account( $items ) {
$items[ 'billing' ] = 'Billing Address'; //The title of new endpoint
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'add_d_link_my_account' );
//4
function d_content() {
echo WC_Shortcode_My_Account::edit_address( 'billing' ); //The content of new endpoint
}
//5
add_action( 'woocommerce_account_billing_endpoint', 'd_content' );
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format
//6
/** Remove Address from My Account Menu **/
add_filter( 'woocommerce_account_menu_items', 'dsx_remove_my_account_dashboard' );
function dsx_remove_my_account_dashboard( $menu_links ) {
unset( $menu_links[ 'edit-address' ] ); //remove the address from endpoint
return $menu_links;
}
然后转到您的Dashboard
> Settings
> Permalinks
,然后单击按钮Save
,应该这样做。
或者,您可以覆盖my-address.php
位于的woocommerce/templates/myaccount
,只需使用WC_Shortcode_My_Account::edit_address( 'billing' );
.
或者您可以重定向到Billing
用户尝试访问Edit-Address
端点时,尝试在您的functions.php
.
function redirect_to_billing( $wp ) {
$current_url = home_url(add_query_arg(array(),$wp->request));
$billing = home_url('/account/edit-address/billing');
/** If user is accessing edit-address endpoint and it's not the billing address**/
if(is_wc_endpoint_url('edit-address') && $current_url !== $billing){
wp_redirect($billing);
exit();
}
}
add_action( 'parse_request', 'redirect_to_billing' , 10);
推荐阅读
- excel - VBA引用当前选择的多单元格范围?
- c# - 使用 Excel 范围使用 ExcelDataReader 读取表格
- python - 在数据框中使用正则表达式提取数字以获取高度(英尺,英寸)
- angular - 为什么 Angular 建议使用 FactoryProvider 来升级 ajs 服务,而不是 InjectionToken?
- scilab - 来自第三个变量的 2D 线条颜色渐变
- php - 检查用户是否在 ExceptionController 中进行了身份验证
- php - 尝试使用 PHP DOMDocument 从 html 页面获取值
- javascript - 骰子滚轮应用程序 - 如何改进数据处理?
- ruby-on-rails - 如何使用 Faraday 和 Rails 5 发送表单数据?
- r - 计算 R 中大量数据帧列表中单独行的模式