Hide Button on checkout page but not order-pay page
-
Hello,
I’m setting up a B2B style website for a client in which prices will not be displayed in the front end and users will have a custom gateway on the checkout page called “Proposal”, so that shop managers can send proposals to customers that request them for items in their cart and then customers can pay when they accept the proposal etc.
I have the following code in my child theme’s functions.php file that disables every payment gateway on the checkout page, except for the custom “Proposal” gateway, but shows the
other available payment gateways (PayPal, Credit Card, Bank Transfers etc) on the Order Pay page for the Order Statuses “Pending” and “Failed”, and of course hides the custom “Proposal” gateway on the order pay page.add_filter( 'woocommerce_available_payment_gateways', 'conditionally_hide_payment_gateways', 100, 1 ); function conditionally_hide_payment_gateways( $available_gateways ) { // 1. On Order Pay page if( is_wc_endpoint_url( 'order-pay' ) ) { // Get an instance of the WC_Order Object $order = wc_get_order( get_query_var('order-pay') ); // Disable Order Proposal gateway only for "pending" and "failed" order status if( $order->has_status('pending') || $order->has_status('failed') ) { unset($available_gateways['orderproposal']); } } // 2. On Checkout page elseif( is_checkout() && ! is_wc_endpoint_url() ) { // Disable every other gateway except order proposal foreach( $available_gateways as $gateways_id => $gateways ){ if($gateways_id != 'orderproposal'){ unset($available_gateways[$gateways_id]); } } } return $available_gateways; }However, my issue with the PayPal Payments extension is, the gold PayPal button still shows up on my Checkout page even though the option to select PayPal as the method is not available/hidden due to the code above. I want the PayPal button to only be visible on the Order Pay page, where users can actually checkout and pay from. In the settings for the PayPal Payments extension, I have the option “Enable buttons on checkout” selected. If I disable this option, it indeed does remove the PayPal button from the checkout page, but also removes PayPal as a payment method to select on the Order Pay page and doesn’t show the PayPal button there either. So far, the only option that works for me is using PayPal standard, but I really like that there’s a PayPal popup when using the PayPal Payments extension, instead of being redirected to PayPal when using the Standard one.
The topic ‘Hide Button on checkout page but not order-pay page’ is closed to new replies.