Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verygoodplugins/a9f314598a1c17d185170bf2a79a579d to your computer and use it in GitHub Desktop.
Save verygoodplugins/a9f314598a1c17d185170bf2a79a579d to your computer and use it in GitHub Desktop.
Makes WP Fusion send Enhanced Ecommerce data when a WooCommerce order is created in Pending status, instead of waiting for Processing
<?php
//
// Makes WP Fusion send Enhanced Ecommerce data when a WooCommerce order is created in Pending status, instead of waiting for Processing
//
function wpf_woocommerce_run_on_pending( $order_id ) {
if ( ! function_exists( 'wp_fusion' ) ) {
return;
}
wp_fusion()->integrations->woocommerce->woocommerce_apply_tags_checkout( $order_id, true );
$order = wc_get_order( $order_id );
// Do some magic here to make it run on Pending orders
if ( 'pending' == $order->get_status() ) {
$user_id = $order->get_user_id();
// Figure out the HubSpot contact ID that was just created
if ( ! empty( $user_id ) ) {
$contact_id = wp_fusion()->user->get_contact_id( $user_id );
} else {
$contact_id = get_post_meta( $order_id, wp_fusion()->crm->slug . '_contact_id', true );
}
if ( ! empty( $contact_id ) ) {
// Denotes that the WPF actions have already run for this order
update_post_meta( $order_id, 'wpf_complete', true );
// Triggers the Enhanced Ecommerce addon to create the deal in HubSpot
do_action( 'wpf_woocommerce_payment_complete', $order_id, $contact_id );
}
}
}
add_action( 'woocommerce_order_status_pending', 'wpf_woocommerce_run_on_pending' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment