Created
October 2, 2020 10:04
-
-
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
This file contains 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
<?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