Ad
In Woocommerce Show The Check Payment Option When An Order Total Is 0 Dollars
On my wordpress, woocommerce website I am trying to add something to the function.php of my theme that will enable the pay with check option if the order total is 0 dollars.
what I have so far:
function payment_gateway_enable_check( $available_gateways ) {
global $woocommerce;
if ( !isset( $available_gateways['check'] ) && $woocommerce->cart->total == 0 ) {
set( $available_gateways['check'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_enable_check' );
Obviously set isn't correct, but I am not sure what to use in place of it.
Ad
Answer
Since the total order is 0 there is no need of payment so woocommerce have woocommerce_cart_needs_payment
which will give false when total is 0 so no payment methods are required.
Just fyi cheque is the name of the gateway not check
//Allow accepting payments if total is 0 (free order)
add_filter( 'woocommerce_cart_needs_payment', '__return_true' );
//Unset payment gateways we dont want if total is 0 (free order)
function payment_gateway_enable_check( $available_gateways ) {
global $woocommerce;
if ( $woocommerce->cart->total == 0 ) {
unset($available_gateways['cod']);
unset($available_gateways['bacs']);
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_enable_check' );
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad