Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HPOS support for wooCommerce #210

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions aftership-woocommerce-tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: AfterShip Tracking - All-In-One WooCommerce Order Tracking (Free plan available)
* Plugin URI: http://aftership.com/
* Description: Track orders in one place. shipment tracking, automated notifications, order lookup, branded tracking page, delivery day prediction
* Version: 1.17.3
* Version: 1.17.4
* Author: AfterShip
* Author URI: http://aftership.com
*
Expand All @@ -20,7 +20,7 @@

require_once( 'woo-includes/woo-functions.php' );

define( 'AFTERSHIP_VERSION', '1.17.3' );
define( 'AFTERSHIP_VERSION', '1.17.4' );
define( 'AFTERSHIP_PATH', dirname( __FILE__ ) );
define( 'AFTERSHIP_ASSETS_URL', plugins_url() . '/' . basename( AFTERSHIP_PATH ) );
define( 'AFTERSHIP_SCRIPT_TAGS', 'aftership_script_tags' );
Expand Down Expand Up @@ -191,6 +191,8 @@ public function __construct() {
// Custom AfterShip Tracking column in admin orders list.
add_filter( 'manage_shop_order_posts_columns', array( $this->actions, 'shop_order_columns' ), 99 );
add_action( 'manage_shop_order_posts_custom_column', array( $this->actions, 'render_shop_order_columns' ) );
add_filter( 'manage_woocommerce_page_wc-orders_columns', array( $this->actions, 'shop_order_columns' ), 99 );
add_action( 'manage_woocommerce_page_wc-orders_custom_column', array( $this->actions, 'render_wc_orders_list_columns' ), 10, 2 );

$subs_version = class_exists( 'WC_Subscriptions' ) && ! empty( WC_Subscriptions::$version ) ? WC_Subscriptions::$version : null;

Expand Down
24 changes: 22 additions & 2 deletions includes/class-aftership-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function load_orders_page_script( $hook ) {
* Add the meta box for shipment info on the order page
*/
public function add_meta_box() {
add_meta_box( 'woocommerce-aftership', __( 'AfterShip', 'aftership' ), array( $this, 'meta_box' ), 'shop_order', 'side', 'high' );
add_meta_box( 'woocommerce-aftership', __( 'AfterShip', 'aftership' ), array( $this, 'meta_box' ), get_order_admin_screen(), 'side', 'high' );
}

/**
Expand Down Expand Up @@ -583,7 +583,11 @@ public function save_tracking_items( $order_id, $tracking_items ) {
// Delete order trackings, $tracking_items may be []
$order->update_meta_data( '_aftership_tracking_number', isset( $tracking_items[0]['tracking_number'] ) ? $tracking_items[0]['tracking_number'] : '' );
$order->update_meta_data( '_aftership_tracking_provider_name', isset( $tracking_items[0]['slug'] ) ? $tracking_items[0]['slug'] : '' );
$order->save_meta_data();
if (custom_orders_table_usage_is_enabled()) {
$order->save();
} else {
$order->save_meta_data();
}
}
}

Expand Down Expand Up @@ -1051,6 +1055,22 @@ public function render_shop_order_columns( $column ) {
}
}

/**
* Render AfterShip tracking in custom column on WC Orders page (when using Custom Order Tables).
*
* @param string $column_name Identifier for the custom column.
* @param \WC_Order $order Current WooCommerce order object.
*
* @return void
* @since 1.8.0
*
*/
public function render_wc_orders_list_columns( $column_name, $order ) {
if ( 'woocommerce-automizely-aftership-tracking' === $column_name ) {
echo wp_kses_post( $this->get_automizely_aftership_tracking_column( $order->get_id() ) );
}
}

/**
* Get content for shipment tracking column.
*
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.aftership.com/
Tags: woocommerce shipping,woocommerce tracking,shipment tracking,order tracking, woocommerce,track order,dhl,ups,usps,fedex,shipping,tracking,order
Requires at least: 2.9
Tested up to: 6.3
Stable tag: 1.17.3
Stable tag: 1.17.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down
24 changes: 24 additions & 0 deletions woo-includes/woo-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ function is_woocommerce_active() {
}
}

if ( ! function_exists( 'wc_order_util_method_exists' ) ) {
function wc_order_util_method_exists($method_name) {
return class_exists('Automattic\WooCommerce\Utilities\OrderUtil') && method_exists('Automattic\WooCommerce\Utilities\OrderUtil', $method_name);
}
}

if ( ! function_exists( 'custom_orders_table_usage_is_enabled' ) ) {
function custom_orders_table_usage_is_enabled() {
if(!wc_order_util_method_exists('custom_orders_table_usage_is_enabled')) {
return false;
}
return call_user_func_array(array('Automattic\WooCommerce\Utilities\OrderUtil', 'custom_orders_table_usage_is_enabled'), array());
}
}

if ( ! function_exists( 'get_order_admin_screen' ) ) {
function get_order_admin_screen() {
if(!wc_order_util_method_exists('get_order_admin_screen')) {
return 'shop_order';
}
return call_user_func_array(array('Automattic\WooCommerce\Utilities\OrderUtil', 'get_order_admin_screen'), array());
}
}

if ( ! function_exists( 'get_order_id' ) ) {
function get_order_id($order) {
return (method_exists($order, 'get_id'))? $order->get_id() : $order->id;
Expand Down
Loading