简体   繁体   English

WooCommerce仅显示登录客户的付款网关

[英]WooCommerce Show Payment Gateways for Logged In Customers Only

I am setting up an ecommerce site using Wordpress and WooCommerce. 我正在使用Wordpress和WooCommerce建立一个电子商务网站。 We are using the wordpress member accounts to track customer information, and we need a way for logged in members only to be able to choose to purchase their cart "on credit", meaning no payment is required to place the order. 我们使用wordpress会员帐户来跟踪客户信息,我们需要一种登录会员的方式, 只能选择“信用”购买他们的购物车,这意味着无需付款即可下订单。 Basically what I have done is hi-jacked the "Check" option (since we don't need it anywhere else) and renamed it "Credit" since it allows for the functionality we need. 基本上我所做的就是“检查”选项(因为我们在其他任何地方都不需要它)并将其重命名为“Credit”,因为它允许我们需要的功能。

However, I need a way for the "Credit" (check) option to only display if the user is logged in. Is there any way I can just "unhook" this option if the user isn't logged in? 但是,我需要一种方法来“信用”(检查)选项,只显示用户是否已登录。如果用户未登录,有什么办法可以“解除”此选项吗? This seems like something that would be easy to do, but I couldn't find anything about it. 这似乎很容易做到,但我找不到任何关于它的东西。 Any help is appreciated. 任何帮助表示赞赏。

The original answer to this question (from BWDesign) no longer works due to changes in WooCommerce (at least from WooCommerce 2.1.7 onwards, possibly before). 这个问题(来自BWDesign)的原始答案不再适用于WooCommerce的变化(至少从WooCommerce 2.1.7开始,可能之前)。 This does the trick now (tested on 2.1.7 and 2.1.8), add it to eg your functions.php file: 这就是现在的技巧(在2.1.7和2.1.8上测试),将它添加到例如你的functions.php文件中:

add_filter( "woocommerce_available_payment_gateways", "rp_filter_gateways", 9999 );

function rp_filter_gateways($args) {
 if(!is_user_logged_in() && isset($args['cheque'])) {
  unset($args['cheque']);
 }
 return $args;
}

I just found the solution. 我刚刚找到了解决方案。 In the class-wc-cheque.php file, the check or "cheque" (crazy brits) option is hooked using add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' ); class-wc-cheque.php文件中,使用add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );挂钩检查或“检查”(疯狂的文件)选项add_filter('woocommerce_payment_gateways', 'add_cheque_gateway' ); . So the solution was simply to add this code to my functions.php file: 所以解决方案只是将此代码添加到我的functions.php文件中:

 if(!is_user_logged_in()){
     remove_filter('woocommerce_payment_gateways', 'add_cheque_gateway' );
 }

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WooCommerce付款网关仅适用于已登录的客户 - WooCommerce Payment Gateways for Logged In Customers Only 根据 Woocommerce 中的延期交货项目显示隐藏支付网关 - Show hide payment gateways based on backordered items in Woocommerce 从WooCommerce中删除支付网关 - Removing payment gateways from WooCommerce 如果优惠券应用于 WooCommerce 中的购物车,则仅显示登录用户的 BACS 支付网关 - Only show BACS payment gateway for logged in users if a coupon is applied to cart in WooCommerce jQuery在付款网关woocommerce上不起作用 - Jquery doesnt work on payment gateways woocommerce 如何在 WooCommerce 中隐藏免费产品的支付网关? - How to hide payment gateways for free products in WooCommerce? WooCommerce结帐上的WordPress多个支付网关选择 - WordPress multiple payment gateways selection on WooCommerce checkout woocommerce信用卡支付网关未显示在“支付网关”页面中 - woocommerce credit card payment gateway not showing up in Payment gateways page 如何仅向在 WooCommerce(使用 Elementor)中购买产品的客户显示小部件? - How to show a widget only to customers who bought a product in WooCommerce (with Elementor)? 添加一个复选框作为 WooCommerce 管理产品选项,禁用支付网关 - Add a checkbox as WooCommerce admin product option that disables payment gateways
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM