Plugin Directory

Changeset 3304669


Ignore:
Timestamp:
06/02/2025 06:48:04 AM (10 months ago)
Author:
api2cartdev
Message:

Added compatibility with WooCommerce 9+

Location:
api2cart-webhook-helper/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • api2cart-webhook-helper/trunk/app/WH_Helper.php

    r3222865 r3304669  
    99{
    1010
    11   const VERSION                    = '1.7';
     11  const VERSION                    = '1.7.3';
    1212  const LANG_DOMAIN                = 'a2c_wh';
    1313
     
    5757    add_action('updated_user_meta', array($this, 'persistentCartUpdated'), 30, 3);
    5858
     59    add_action('woocommerce_before_order_object_save', array($this, 'beforeOrderSave'), 10, 1);
     60    add_action('woocommerce_after_order_object_save', array($this, 'afterOrderSave'), 10, 1);
     61
    5962    add_action( 'add_post_meta', array( $this, 'insertShipment' ), 29, 3);
    6063    add_action( 'update_post_meta', array( $this, 'beforeShipmentUpdate' ), 29, 4);
     
    9396
    9497  /**
     98   * @return bool
     99   */
     100  private function _is_hpos_enabled() {
     101    if ( !function_exists('wc_get_container') ) {
     102      return false;
     103    }
     104
     105    $container = wc_get_container();
     106
     107    if ( !class_exists('\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' )
     108      || !$container->has( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )
     109    ) {
     110      return false;
     111    }
     112
     113    $controller = $container->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class );
     114
     115    return method_exists( $controller, 'custom_orders_table_usage_is_enabled' ) && $controller->custom_orders_table_usage_is_enabled();
     116  }
     117
     118  /**
     119   * @param $order
     120   */
     121  public function beforeOrderSave( $order ) {
     122    if ( !is_a( $order, 'WC_Order' )) {
     123      return;
     124    }
     125
     126    global $wpdb;
     127
     128    $meta_table = $this->_is_hpos_enabled() ? $wpdb->prefix . 'wc_orders_meta' : $wpdb->postmeta;
     129    $id_field = $this->_is_hpos_enabled() ? 'order_id' : 'post_id';
     130
     131    $raw_value = $wpdb->get_var(
     132      $wpdb->prepare(
     133        "SELECT meta_value FROM {$meta_table} WHERE {$id_field} = %d AND meta_key = %s LIMIT 1",
     134        $order->get_id(),
     135        self::METAKEY_SHIPMENT_TRACKING
     136      )
     137    );
     138
     139    $this->_tracking = maybe_unserialize( $raw_value ) ?: [];
     140  }
     141
     142  /**
     143   * @param $order
     144   */
     145  public function afterOrderSave( $order )
     146  {
     147    if ( !is_a( $order, 'WC_Order' ) ) {
     148      return;
     149    }
     150
     151    $current = $order->get_meta( self::METAKEY_SHIPMENT_TRACKING, true );
     152
     153    if ( $current !== '' && $this->_tracking !== $current ) {
     154      $this->afterShipmentUpdate( 0, $order->get_id(), self::METAKEY_SHIPMENT_TRACKING, $current );
     155    }
     156  }
     157
     158  /**
    95159   * @param $meta_id
    96160   * @param $object_id
     
    154218      }
    155219
    156       $currentTracking = isset(get_post_meta_by_id($meta_id)->meta_value) ? get_post_meta_by_id($meta_id)->meta_value : [];
    157 
     220      $currentTracking = $meta_value;
    158221      $countCurrentTracking = count($currentTracking);
    159222      $countExistTracking = $this->_tracking ? count($this->_tracking) : 0;
     
    173236          do_action( 'a2c_wh_shipment_deleted_action', $this->_shipmentData($deletedTracking, $object_id, $deletedTracking['tracking_id']));
    174237        } else {
    175           do_action('a2c_wh_shipment_updated_action', $this->_shipmentData($deletedTracking, $object_id));
     238          do_action('a2c_wh_shipment_deleted_action', $this->_shipmentData($deletedTracking, $object_id));
    176239        }
    177240      } elseif ($countCurrentTracking > $countExistTracking) {
  • api2cart-webhook-helper/trunk/readme.txt

    r3284789 r3304669  
    55Requires at least: 4.1
    66Tested up to: 6.8
    7 Stable tag: 1.7.2
     7Stable tag: 1.7.3
    88License:      GPL2
    99License URI:  https://www.gnu.org/licenses/gpl-2.0.html
     
    4848
    4949== Changelog ==
     50= 1.7.3 =
     51* Added compatibility with WooCommerce 9+
     52
    5053= 1.7.2 =
    5154* Fix bugs
Note: See TracChangeset for help on using the changeset viewer.