• Resolved turnover2

    (@turnover2)


    HI all , Below code hides the order button on checkout page when there are no available shipping methods. But unfortuntely unable to hide the paypal button in your plugin please suggest how to hide paypal button at checkout .

    This code works for me. It hides the "checkout" button on checkout page if there are no available shipping methods. Goes into your child theme's functions.php.
    
    //Hide checkout button if no shipping is available
    add_filter('woocommerce_order_button_html', 'hide_checkout_button__no_shipping_html' );
    function hide_checkout_button__no_shipping_html( $button ) {
    
        $package_counts = array();
        $packages = WC()->shipping->get_packages();
        foreach( $packages as $key => $pkg ) {
            $package_counts[ $key ] = count( $pkg[ 'rates' ] );
        }
    
        if( in_array( 0, $package_counts ) ) { //no available shipping method
            $button = '';
        }

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Payment Plugins

    (@mrclayton)

    Hi @turnover2

    Do you prefer to have the PayPal button where the Place Order button is? There is an option within the PayPal Settings page where you can render the PayPal button within the payment methods section that doesn’t require any code.

    Kind Regards,

    Thread Starter turnover2

    (@turnover2)

    Hi thanks for the reply ,

    Please have a look at checkout page , the paypal button is there itself at place order button but it needs to hide with the code as other buttons are hiding.

    Please visit https://sab1000.com select a physical product in the cart >> select state berlin at checkout >> and have a look at order place buttons . From other payment options buttons hide except Payment plugins Paypal button ( also WPS paypal button hides ) please suggest how to hide Paypal button when no shipping is available.

    Plugin Author Payment Plugins

    (@mrclayton)

    You can use CSS selectors to hide the PayPal button based on custom conditions. In the woocommerce/templates/checkoutpayment.php template you can copy that to your theme and add a custom CSS class to the html element with class woocommerce-checkout-payment when there are no shipping options.

    Then with CSS write something like:

    .no-shipping .wc-ppcp-checkout-container{
        display: none;
    }

    Kind Regards,

    Thread Starter turnover2

    (@turnover2)

    I am using this code in fun.php

    //Hide checkout button if no shipping is available
    add_filter('woocommerce_order_button_html', 'hide_checkout_button__no_shipping_html' );
    function hide_checkout_button__no_shipping_html( $button ) {
    
        $package_counts = array();
        $packages = WC()->shipping->get_packages();
        foreach( $packages as $key => $pkg ) {
            $package_counts[ $key ] = count( $pkg[ 'rates' ] );
        }
    
        if( in_array( 0, $package_counts ) ) { //no available shipping method
            $button = '';
        }
        return $button;
    }

    After your reply I could copy the payment.php fiel to Childtheme >>woocommerce >> payment.php and have added the css code in the custom css area in Dashboard >> Design >> Customiser >> CSS Please share the documentation how to add a custom CSS class to the html element with class?woocommerce-checkout-payment?when there are no shipping options.

    Do i need to paste the same above code in the payment.php also ?please advise

    Plugin Author Payment Plugins

    (@mrclayton)

    Do i need to paste the same above code in the payment.php also

    I’d recommend you place your code in a custom function, that way you can reference it anywhere you like. Then you can add the desired class based on the outcome of the function.

    <div id="payment" class="woocommerce-checkout-payment <?php echo custom_does_checkout_have_shipping_options() ? 'no-shipping' : ''?>">
    
    </div>
    Thread Starter turnover2

    (@turnover2)

    thanks but unfortunately the paypal button is not hidden on the condition, i would be grateful if you have a look on the steps below from my backend

    child theme >> fun.php >> code added

    //Hide checkout button if no shipping is available add_filter(‘woocommerce_order_button_html’, ‘hide_checkout_button__no_shipping_html’ ); function hide_checkout_button__no_shipping_html( $button ) { $package_counts = array(); $packages = WC()->shipping->get_packages(); foreach( $packages as $key => $pkg ) { $package_counts[ $key ] = count( $pkg[ ‘rates’ ] ); } if( in_array( 0, $package_counts ) ) { //no available shipping method $button = ”; } return $button; }

    step 2. copied the file from path woocommerce/templates/checkoutpayment.php pasted to child theme/ woocommerce /payment.php – added the div class in child theme/ woocommerce /payment.php line 62

    <div id="payment" class="woocommerce-checkout-payment <?php echo custom_does_checkout_have_shipping_options() ? 'no-shipping' : ''?>"> </div>
    
    

    added css

    .no-shipping .wc-ppcp-checkout-container{ display: none; }

    please help me resolve this.

    Plugin Author Payment Plugins

    (@mrclayton)

    It’s not working because you actually need to make a function called custom_does_checkout_have_shipping_options or whatever you want to call it, that returns true or false, based on if there are shipping options or not.

    added the div class in child theme/ woocommerce /payment.php line 62

    You don’t add that HTML, it already exists on line 24 of payment.php. You just need to modify the existing HTML.

    Thread Starter turnover2

    (@turnover2)

    <div id="payment" class="woocommerce-checkout-payment <?php echo custom_does_checkout_have_shipping_options() ? 'no-shipping' : ''?>">
    	<?php if ( WC()->cart->needs_payment() ) : ?>

    Line 24 is in edited accordingly still the calling function is not accepted and after checking on staging site the plugin paypal payments doesnot need extra coding to hide the paypal button. Is there anyway you could further help me to hide the paypal button in your plugin Please advice how to proceed ?

    Plugin Author Payment Plugins

    (@mrclayton)

    after checking on staging site the plugin paypal payments doesnot need extra coding to hide the paypal button.

    Then my recommendation is to just use that plugin if it’s giving you the functionality you want without additional coding.

    The function custom_does_checkout_have_shipping_options in the example code is a placeholder. You need to actually create a function called custom_does_checkout_have_shipping_options or whatever you want to name it. That function needs to return true or false based on if there are shipping methods.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘hide paypal button when no shipping available’ is closed to new replies.