Skip to content

Instantly share code, notes, and snippets.

@davidwebca
Created September 26, 2022 21:24
Show Gist options
  • Save davidwebca/65375178f8626557b69df6742bd973a6 to your computer and use it in GitHub Desktop.
Save davidwebca/65375178f8626557b69df6742bd973a6 to your computer and use it in GitHub Desktop.
Fix learndash_woocommerce.php + WooCommerce Subscription rollback issue
<?php
/**
* Theme filters.
*/
namespace App;
/**
* Fix checkout bug with learndash_woocommerce
*
* learndash_woocommerce.php:580
* learndash_woocommerce.php:606
*
* Those lines use $_POST['customer_user'] regardless of admin or frontend and cause a fatal error
* since the key doesn't exist (or doesn't always exist) on frontend checkout process. WooCommerce Subscription
* then rollbacks its transaction that saves the subscription line line items to the subscription, hence not
* being able to see the amounts, renew manually, deactivate renewals or plainly being unable to renew orders.
*/
function make_sure_post_key_exists_to_a_null_value($order_id) {
if(!isset($_POST['customer_user'])) {
$order = wc_get_order( $order_id );
$_POST['customer_user'] = $order->get_customer_id();
}
}
add_action('woocommerce_process_shop_order_meta', __NAMESPACE__ . '\\make_sure_post_key_exists_to_a_null_value', 0, 1);
add_action('woocommerce_before_subscription_object_save', __NAMESPACE__ . '\\make_sure_post_key_exists_to_a_null_value', 0, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment