woocommerce / facebook-for-woocommerce

A first-party extension plugin built for WooCommerce. Development is managed by Ventures.
https://woocommerce.com/products/facebook/
GNU General Public License v2.0
211 stars 140 forks source link

Trigger purchase event on custom order status #2735

Closed sanesh-acowebs closed 6 months ago

sanesh-acowebs commented 6 months ago

Do you have any options for triggering a purchase event on a custom order status?

rawdreeg commented 6 months ago

Hi @sanesh-acowebs,

Can you provide more details on what you're trying to do? The purchase event is triggered when the order is placed or checked out. Do you want to change when this happens?

sanesh-acowebs commented 6 months ago

Hi, We are using the deposit plugin for partial payment. So we have the option to pay the full amount or a partial amount. The issue that we are facing is that when a customer pays the full amount (as a normal order) its purchase events are correctly registered with Facebook. But when we try to make a partial payment, it is not registered. When we try to pay using partial payment, a new custom order status "partially paid" is used for tracking. So want to know whether there are any filters available to add custom order status in the purchase event.  

rawdreeg commented 6 months ago

Thanks for clarifying. I looked into this, and we only trigger the purchase event post-checkout with a fallback that runs on the thankyou_page. There are no filters to trigger this event at the moment.

sanesh-acowebs commented 6 months ago

Thanks for your reply. Can you give a little more clarity about the changes required. Currently, we are only changing the order status to "partially paid" other than normal "processing or completed". 

rawdreeg commented 6 months ago

We only trigger a purchase event once the checkout is completed. If you want a purchase to be sent when the status changes, this might require some custom logic. For example:


add_action('woocommerce_order_status_changed', 'send_purchase_event', 10, 3);

function send_purchase_event($order_id, $old_status, $new_status) {
    $order = wc_get_order($order_id);
    if ( ! $order ) {
        return;
    }

    if ( 'your new status' === $new_status ) {
        if ( function_exists( 'facebook_for_woocommerce' ) ) {
            facebook_for_woocommerce()->get_integration()->events_tracker->inject_purchase_event($order_id);
        }
    }
}

However, I recommend against something like this as it uses the plugin's internal code, which may be subject to change. You can also add a feature request for this, and our team will review: https://woocommerce.com/feature-requests/facebook/

sanesh-acowebs commented 6 months ago

We have created a new feature request on the shared link. And also we will check the shared code and share our comments. Thanks.