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,
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.
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,
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
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>
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.
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.
<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 ?
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.
-
This reply was modified 3 years, 3 months ago by
Clayton R.