Warning: Trying to access array offset on value of type bool in /www/wwwroot/weimahe.com/wp-content/advanced-cache.php on line 472

Warning: Trying to access array offset on value of type bool in /www/wwwroot/weimahe.com/wp-content/advanced-cache.php on line 472
WooCommerce 购物车中只有虚拟商品时移除不必要的结账字段 - 微码盒
!
也想出现在这里? 联系我们
广告位

WooCommerce 购物车中只有虚拟商品时移除不必要的结账字段

如果我们使用 WooCommerce 发布了一个虚拟产品——如付费下载资源用户购买后,可以直接下载,不需要发送商品或账单给顾客,这个时候,结账页面的收件地址字段明显是多余的。

* ? 0 \ = U果结账时, 顾客的订单中只有虚拟商品时,我们可以移除收货地址字段,a | 3 4 3 M Z 6减少要求用户填写的内容,以提高结账效率。实h X . z现这个需求的关键是判断购物车中只有虚拟商品。

我们可以遍历购物车中的商品来进行判断,只要有一个商品不是虚拟商品,移除收货地址字段这个条件就3 d U Z G不成立,具体参考下面! } ) |代码

  1. add_filter('woocommerce_checkout_fields', function &* % i q / H#040;$fieldq v : -s)
  2. / ~ O 0 q w ] %3;
  3. $only_virtual = true;
  4. foreach (WC()->cart->get_ca, R ;rt() as $cart_itJ ] ? j p Tem_key => $cart_item) 9 G H = t123;
  5. // ChE - Y Xeck if there are4 { @ Y V F X non-virtual products
  6. if ( ! $cart_item[ 'data' ]-&; [ S K m n cgt;is_vir& ( I . S e U atual&0 # i E 9#040;)) {
  7. $only_virtual = false;
  8. }
  9. t = 8 y S ~ /5;
  10. if ($only_virtual) {
  11. unset($fields[ 'billW 2 d T i D B Ming' ][ 'billing_first_name' ]);
  12. unA V | ( \ * !set($fields[ 'billing' &0 G o 7 I#093;[ 'billing_last_name' ]);
  13. unset($fields[ 'billing' ][ 'billing_emaB i \ l Eil' ]);
  14. unset($fields[ 'billing' ][ 'billing_company' ]);
  15. unset($fields[ 'billing' ] ? t ~ / P F 8 C 71; 'A s 4billing_address_1' ]);
  16. unset($fields[ 'billing' ][ 'biA 3 K w G ! t $ Dlling_address_2' ]);
  17. unset($fields[ 'billing' ][ 'billing_city' ]);
  18. unsetX ~ G r 1 b040;$fields[ 'billc \ N c W } Ring' ][ 'billing_posO T htcode' ]);
  19. unset($fielK z B g / = x P :ds[ 'billing'S ! . 5 - h % ) ]e [ | c 5 J E h R;[ 'billi2 H P I 8 2 Bng_country' ]);
  20. unset($fields[ 'billing' ][ 'billing_state' ]);
  21. unset($fields[ 'billit F | Hng' ]f c K O g { i _ 91; 'billing_phone' ]);
  22. add_filter&u m l . b B , \ B#040;'woocommerce_enable_order_notes_field', '__return_false');
  23. }
  24. re} ; [ D $ Q d R Kturn $fields;
  25. });

给TA打赏
共{{data.count}}人
人已打赏
WordPress教程

使用 WP User Frontend 插件添加自定义页面到我的账户

2022-10-2 15:48:55

WordPress教程

WooCommerce 使用 PayPal 收款添加手续费

2022-10-3 15:50:23

下载说明

  • 1、微码盒所提供的压缩包若无特别说明,解压密码均为weimahe.com
  • 2、下载后文件若为压缩包格式,请安装7Z软件或者其它压缩软件进行解压;
  • 3、文件比较大的时候,建议使用下载工具进行下载,浏览器下载有时候会自动中断,导致下载错误;
  • 4、资源可能会由于内容问题被和谐,导致下载链接不可用,遇到此问题,请到文章页面进行反馈,以便微码盒及时进行更新;
  • 5、其他下载问题请自行搜索教程,这里不一一讲解。

站长声明

本站大部分下载资源收集于网络,只做学习和交流使用,版权归原作者所有;若为付费资源,请在下载后24小时之内自觉删除;若作商业用途,请到原网站购买;由于未及时购买和付费发生的侵权行为,与本站无关。本站发布的内容若侵犯到您的权益,请联系本站删除,我们将及时处理!
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索