Plugin Directory

Changeset 3021399


Ignore:
Timestamp:
01/13/2024 06:57:12 PM (2 years ago)
Author:
spanrig
Message:

Update: Added Compatibility with Woocommerce HPOS

Location:
utm-for-woocommerce
Files:
20 added
5 edited

Legend:

Unmodified
Added
Removed
  • utm-for-woocommerce/trunk/core/class-utm-for-woocommerce.php

    r3020025 r3021399  
    137137        private function base_hooks() {
    138138            add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
     139            add_action('before_woocommerce_init', array( self::$instance, 'utmforwoo_add_hpos_compatibility'));
    139140        }
    140141
     
    150151        }
    151152
     153        /**
     154         * Adds compatibility with Woocommerce HPOS.
     155         *
     156         * @access  public
     157         * @since   1.0.0
     158         * @return  void
     159         */
     160        public function utmforwoo_add_hpos_compatibility(){
     161            if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     162                \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', UTMFORWOO_PLUGIN_FILE, true );
     163            }
     164        }
     165
    152166    }
    153167
  • utm-for-woocommerce/trunk/core/includes/classes/class-utm-for-woocommerce-helpers.php

    r3020025 r3021399  
    4545
    4646        /**
     47         * Get the order object with HPOS compatibility.
     48         *
     49         * @param WC_Order|WP_Post|int $post_or_order The post ID or object.
     50         *
     51         * @return WC_Order The order object
     52         * @throws Exception When the order isn't found.
     53         */
     54        public function ufw_get_hpos_order_object( $post_or_order ) {
     55            // If we've already got an order object, just return it.
     56            if ( $post_or_order instanceof WC_Order ) {
     57                return $post_or_order;
     58            }
     59
     60            // If we have a post ID, get the post object.
     61            if ( is_numeric( $post_or_order ) ) {
     62                $post_or_order = wc_get_order( $post_or_order );
     63            }
     64
     65            // Throw an exception if we don't have an order object.
     66            if ( ! $post_or_order instanceof WC_Order ) {
     67                throw new Exception( __( 'Order not found.', 'woocommerce' ) );
     68            }
     69
     70            return $post_or_order;
     71        }
     72
     73        /**
    4774         * HELPER COMMENT END
    4875        */
  • utm-for-woocommerce/trunk/core/includes/classes/class-utm-for-woocommerce-run.php

    r3020025 r3021399  
    8080         */
    8181        private function add_hooks(){
    82        
     82           
    8383            add_action( 'plugin_action_links_' . UTMFORWOO_PLUGIN_BASE, array( $this, 'utmforwoo_add_plugin_action_link' ), 20 );
    8484
     
    8888
    8989            add_filter('manage_edit-shop_order_columns', array( $this, 'utmforwoo_add_utm_and_clid_order_columns'), 20);
    90 
    91             add_action('manage_shop_order_posts_custom_column', array( $this, 'utmforwoo_add_utm_and_clid_order_column_content'));
     90           
     91            add_filter('manage_woocommerce_page_wc-orders_columns', array( $this, 'utmforwoo_add_utm_and_clid_order_columns'), 20);
     92
     93            add_action('manage_shop_order_posts_custom_column', array( $this, 'utmforwoo_add_utm_and_clid_order_column_content'), 10, 2);
     94
     95            add_action('manage_woocommerce_page_wc-orders_custom_column', array( $this, 'utmforwoo_add_utm_and_clid_order_column_content'), 10, 2);
     96
     97            add_action( 'add_meta_boxes', array($this, 'utmforwoo_order_meta_box' ));
    9298
    9399            add_filter('woo_ca_session_abandoned_data', array( $this, 'utmforwoo_save_utm_in_wcf'), 10);
    94        
    95         }
     100
     101        }
     102
     103       
    96104
    97105        /**
     
    156164         * This function takes an order ID as a parameter. It then defines a list of parameters that we want to save.
    157165         * It loops through each parameter and checks if the parameter is set in the session. If the parameter is set,
    158          * it saves it to the order meta using the update_post_meta function.
     166         * it saves it to the order meta using the update_meta_data function.
    159167         *
    160168         * @param int $order_id The ID of the order to which the parameters should be saved.
     
    162170         */
    163171        public function utmforwoo_save_utm_and_clid_order_meta($order_id) {
     172            $order = UTMFORWOO()->helpers->ufw_get_hpos_order_object( $order_id );
    164173            $parameters = $this->params;
    165        
     174
    166175            foreach ($parameters as $parameter) {
    167176                if (isset($_SESSION[$parameter])) {
    168                     update_post_meta($order_id, $parameter, sanitize_text_field($_SESSION[$parameter]));
    169                 }
    170             }
     177                    $order->update_meta_data( $parameter, sanitize_text_field($_SESSION[$parameter]) );
     178                }
     179            }
     180            $order->save();
     181        }
     182
     183        /**
     184         * Add meta box to the Order edit screen.
     185         *
     186         * @return void
     187         */
     188        public function utmforwoo_order_meta_box() {
     189            add_meta_box(
     190                'utmforwoo_order_meta_box',
     191                __( 'UTM for WOO Order Tracking Information', 'woocommerce' ),
     192                array($this, 'utmforwoo_order_meta_box_callback'),
     193                'shop_order',
     194                'side',
     195                'core'
     196            );
     197        }
     198
     199
     200        /**
     201         * Callback function for UTM for WOO Tracking Information meta box.
     202         *
     203         * @param object $post Post object.
     204         *
     205         * @return void
     206         */
     207        function utmforwoo_order_meta_box_callback( $post ) {
     208
     209            $order = UTMFORWOO()->helpers->ufw_get_hpos_order_object( $post->ID );
     210
     211            $parameters = $this->params;
     212            echo '<table style="width: 100%;">';
     213            foreach ($parameters as $parameter) {
     214                    echo '<tr><td>'.ucwords(str_replace('_', ' ', $parameter)).'</td><td>'.$order->get_meta( $parameter, true ).'</td></tr>';
     215            }
     216            echo '</table>';
    171217        }
    172218
     
    251297         * @return void
    252298         */
    253         public function utmforwoo_add_utm_and_clid_order_column_content($column) {
    254             global $post;
    255        
    256             if (in_array($column, $this->params)) {
    257                 $value = get_post_meta($post->ID, $column, true);
    258        
    259                 if (!empty($value)) {
    260                     echo esc_html($value);
    261                 } else {
    262                     echo '-';
    263                 }
    264             }
     299        public function utmforwoo_add_utm_and_clid_order_column_content($column, $order_id) {
     300       
     301            try {
     302               
     303                if (in_array($column, $this->params)) {
     304                    $order = UTMFORWOO()->helpers->ufw_get_hpos_order_object( $order_id );
     305                    $value = $order->get_meta($column);
     306           
     307                    if (!empty($value)) {
     308                        echo esc_html($value);
     309                    } else {
     310                        echo '-';
     311                    }
     312                }
     313               
     314            } catch ( Exception $e ) {
     315                return;
     316            }
     317           
    265318        }
    266319
  • utm-for-woocommerce/trunk/readme.txt

    r3020007 r3021399  
    2323
    2424No longer constrained by the arduous task of reconciling numbers and navigating multiple platforms, UTM for WooCommerce empowers store owners to focus on what matters most – optimizing marketing strategies and driving business success. Join the thousands of store owners who have benefited from our solution, and make UTM for WooCommerce an integral part of your toolkit for unparalleled insights and seamless analytics.
     25
     26Note: Compatible with Woocommerce HPOS
    2527
    2628== Frequently Asked Questions ==
     
    6870= 1.0.0: January 2, 2024 =
    6971* Birthday of UTM for Woocommerce
     72
     73= 1.0.1: January 14, 2024 =
     74* Added compatibility with Woocommerce HPOS
  • utm-for-woocommerce/trunk/utm-for-woocommerce.php

    r3020025 r3021399  
    66 * @author        Spanrig Technologies
    77 * @license       gplv3-or-later
    8  * @version       1.0.0
     8 * @version       1.0.1
    99 *
    1010 * @wordpress-plugin
     
    1212 * Plugin URI:    https://spanrig.com
    1313 * Description:   Simply track UTM parameters in Woocommerce orders.
    14  * Version:       1.0.0
     14 * Version:       1.0.1
    1515 * Author:        Spanrig Technologies
    1616 * Author URI:    https://www.upwork.com/fl/hncvj
     
    4848
    4949// Plugin version
    50 define( 'UTMFORWOO_VERSION',        '1.0.0' );
     50define( 'UTMFORWOO_VERSION',        '1.0.1' );
    5151
    5252// Plugin Root File
Note: See TracChangeset for help on using the changeset viewer.