• Resolved Selah

    (@tubescreamer)


    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.

    • This topic was modified 4 years, 7 months ago by Selah.
    • This topic was modified 4 years, 7 months ago by Selah.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Syde Niklas

    (@niklasinpsyde)

    Hi @tubescreamer,

    Can you please try clearing your browser cache and also activate the default theme Storefront?
    I just tested your code and it appears to work as intended for me.
    With bacs and PayPal Payments enabled & the filter applied (changing orderproposal gateway with bacs), I only see bacs in the regular checkout.
    There are no PayPal buttons visible for me in the regular checkout without the gateway being visible. Could you maybe share a screenshot of how this looks like for you?

    When trying to pay for a “Pending payment” order from the order-pay site, I am only presented with PayPal Payments as a payment method and bacs is hidden. So all appears to be fine with no unintended PayPal buttons anywhere.

    Kind regards,
    Niklas

    Thread Starter Selah

    (@tubescreamer)

    Hmm, that’s strage. It seems to be working now. Guess it was a caching issue.

    However, as much as I like the fact that this plugin has the gold PayPal button and the popup on my site to complete the payment instead of being redirected to PayPal like PayPal Standard does, it does seem quite buggy for me. For example, for some reason when I checkout using your plugin, it adds an extra product image to the order table in the New Order and Processing order emails that I have already designed with Kadence WooCommerce email designer plugin, as well as my PDF Invoice that is generated by the PDF Invoices and Packing Slips plugin. I’m not exactly sure why this plugin is doing that, but PayPal Standard payment gateway doesn’t do this, nor do any of the other Payment gateways I have installed.

    Thread Starter Selah

    (@tubescreamer)

    Hmm.. well it seems that a piece of custom code that I added to show product thumbnails on the order-received and order-pay WC endpoints are what’s causing these extra product images to be added.. However it’s strange that only when using your payment gateway, this occurs.

    I’m not sure how my code would affect this:

    add_filter( 'woocommerce_order_item_name', 'order_received_item_thumbnail_image', 10, 3 );
    function order_received_item_thumbnail_image( $item_name, $item, $is_visible ) {
        // Targeting order received page only
        if( ! is_wc_endpoint_url('order-received') ) return $item_name;
    
        // Get the WC_Product object (from order item)
        $product = $item->get_product();
    
        if( $product->get_image_id() > 0 ){
            $product_image = '<div class="order-pay-product-image">' . $product->get_image(array(300, 300)) . '</div>';
            $item_name = $product_image . $item_name;
        }
    
        return $item_name;
    }
    
    add_filter( 'woocommerce_order_item_name', 'order_pay_item_thumbnail_image', 10, 3 );
    function order_pay_item_thumbnail_image( $item_name, $item, $is_visible ) {
        // Targeting order pay page only
        if( ! is_wc_endpoint_url('order-pay') ) return $item_name;
    
        // Get the WC_Product object (from order item)
        $product = $item->get_product();
    
        if( $product->get_image_id() > 0 ){
            $product_image = '<div class="order-pay-product-image">' . $product->get_image(array(300, 300)) . '</div>';
            $item_name = $product_image . $item_name;
        }
    
        return $item_name;
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Hide Button on checkout page but not order-pay page’ is closed to new replies.