Created
June 7, 2025 12:33
-
-
Save xlplugins/21c476981d21f47cc18ca663bb184011 to your computer and use it in GitHub Desktop.
Save log for during the checkout process for checking Subscription created?.
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
class Funnekit_Save_log_Subscription_function_runs { | |
public function __construct() { | |
add_action( 'woocommerce_checkout_process', [ $this, 'log_subscription' ] ); | |
add_action( 'woocommerce_checkout_order_processed', array( $this, 'log_subscription' ), 101 ); | |
add_action( 'subscriptions_created_for_order', array( $this, 'log_subscription' ), 101 ); | |
add_action( 'woocommerce_checkout_subscription_created', array( $this, 'log_subscription' ), 101 ); | |
} | |
public function log_subscription( $order = null ) { | |
try { | |
$products = []; | |
if ( ! is_null( WC()->cart ) && ! WC()->cart->is_empty() ) { | |
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
$products[] = $cart_item['data']->get_name(); | |
} | |
} | |
$order_id = 0; | |
if ( $order instanceof WC_Order ) { | |
$order_id = $order->get_id(); | |
} | |
wc_get_logger()->debug( print_r( [ current_action(), $order_id, WC_Subscriptions_Cart::cart_contains_subscription(), $_POST, $products ], true ), [ 'source' => 'funnelkit-dev' ] ); | |
} catch ( \Exception|\Exception$e ) { | |
} | |
} | |
} | |
new Funnekit_Save_log_Subscription_function_runs(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment