• Making GTM4WP compatible with high performance order storage (HPOS)

    EDIT: Please see second post of this thread.

    To make this plugin compatible with HPOS, you only need to change 4 code blocks in one file, and then add the compatibility flag.

    The file: /integrations/woocommerce.php

    As of writing this, you need to change blocks on lines 843, 863, 1015, and 1044.

    Change line 843 from this:

    if ( ( 1 === (int) get_post_meta( $order_id, '_ga_tracked', true ) ) && ! $do_not_flag_tracked_order ) {
        unset( $order );
    }

    To this:

    if ( ( 1 === (int) $order->get_meta('_ga_tracked') ) && ! $do_not_flag_tracked_order ) {
        unset( $order );
    }

    Change line 863 from this:

    if ( ! $do_not_flag_tracked_order ) {
        update_post_meta( $order_id, '_ga_tracked', 1 );
    }

    To this:

    if ( ! $do_not_flag_tracked_order ) {
        $order->update_meta_data('_ga_tracked', 1 );
        $order->save();
    }

    Change line 1015 from this:

    if ( ( 1 === (int) get_post_meta( $order_id, '_ga_tracked', true ) ) && ! $do_not_flag_tracked_order ) {
        unset( $order );
    }

    To this:

    if ( ( 1 === (int) $order->get_meta('_ga_tracked') ) && ! $do_not_flag_tracked_order ) {
        unset( $order );
    }

    Change line 1044 from this:

    if ( ! $do_not_flag_tracked_order ) {
        update_post_meta( $order_id, '_ga_tracked', 1 );
    }

    To this:

    if ( ! $do_not_flag_tracked_order ) {
        $order->update_meta_data('_ga_tracked', 1);
        $order->save();
    }

    After that you can open the file duracelltomi-google-tag-manager-for-wordpress.php in the root folder of the plugin. At the bottom of this file, add this code block:

    add_action( 'before_woocommerce_init', function() {
    	if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
    		\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
    	}
    } );

    I will submit these changes as a pull request to the author on GitHub, but the author seems to have been AFK for some time.

    Let’s hope it gets implemented soon!

    • This topic was modified 1 year, 3 months ago by Dekadinious.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘This is how you make the plugin compatible with High Performance Order Storage’ is closed to new replies.