Created
January 11, 2022 17:33
-
-
Save atanasantonov/ee95ef2295d8360a6e4fc35613d2dd49 to your computer and use it in GitHub Desktop.
Fix Deliver with Econt checkout process for virtual products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Fix Deliver with Econt checkout process. | |
* | |
* Check cart for virtual products and remove action 'action_woocommerce_checkout_process' | |
* hooked in plugins/deliver-with-econt/bootstrap.php:393 if there are only | |
* virtual products. | |
*/ | |
function fix_econt_checkout_process() { | |
// Change this to 0 to disable logging. | |
$logging = 1; | |
// Initial values of products count. | |
$virtual = 0; | |
$physical = 0; | |
// Check cart contents. | |
foreach( WC()->cart->get_cart() as $item ) { | |
if( empty( $item['product_id'] ) ) { | |
continue; | |
} | |
$product = wc_get_product( $item['product_id'] ); | |
if( empty( $product ) ) { | |
continue; | |
} | |
$product->is_virtual() ? $virtual++ : $physical++; | |
$product_id = $cart_item['product_id']; | |
} | |
// Add log data. | |
$log = sprintf( 'Fix Econt checkout process: virtual=%d, physical=%d;', $virtual, $physical ); | |
if ( ! empty( $virtual ) && empty( $physical ) ) { | |
remove_action( 'woocommerce_checkout_process', 'action_woocommerce_checkout_process' ); | |
$log .= ' Action [action_woocommerce_checkout_process] removed'; | |
} | |
// Add log. | |
if ( ! empty( $logging ) && function_exists( 'wc_get_logger' ) ) { | |
wc_get_logger()->debug( $log ); | |
} | |
} | |
add_action( 'woocommerce_before_checkout_process', 'fix_econt_checkout_process' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment