Skip to content

Instantly share code, notes, and snippets.

@trackship
trackship / Replace text from tracking events
Last active November 2, 2022 11:47
replace string from tracking event location
/**
* Replace text in the tracking events description
*/
add_filter( 'trackship_tracking_event_description', 'replace_text_tracking_event_description', 10, 1 );
function replace_text_tracking_event_description( $message ) {
// Add the text in $search and $replace array
$search = array(
"Mariam", // you can add multiple rows
);
$replace = 'Masdar City';
@trackship
trackship / integrately_callback.php
Last active January 21, 2025 10:33
Shipment status change event trigger hook
<?php
/**
* Triggered when a shipment status changes in TrackShip.
* This callback function handles the custom action `ts_status_change_trigger` and sends a POST request
* to an Integrately webhook URL to synchronize shipment updates.
* Use this hook to execute custom actions, such as sending data to third-party platforms or triggering webhooks.
*
* @param int $order_id The WooCommerce order ID.
* @param string $old_status The previous shipment status.
@trackship
trackship / exclude_to_send_trackship.php
Last active September 14, 2022 05:46
Do not send data to TrackShip for specific provider
// Do not send data to TrackShip for specific provider
add_filter( 'exclude_to_send_data_for_provider', 'exclude_to_send_data_for_provider', 10, 2 );
function exclude_to_send_data_for_provider( $bool, $tracking_provider ) {
// Add your provider slug to this array for do not send data for provider
$array = array(
'usps',
'fedex'
);
return in_array( $tracking_provider, $array ) ? false : true;
}
@trackship
trackship / jwt-auth-whitelist-codesnippet.txt
Last active July 29, 2022 06:24
Every call to the server (except the token creation some default whitelist) will be intercepted. However, you might need to whitelist some endpoints. You can use jwt_auth_whitelist filter to do it. Please simply add this filter directly (without hook). Or, you can add it to plugins_loaded. Adding this filter inside init (or later) will not work.
// TrackShip endpoint for whitelist from jwt
add_filter( 'jwt_auth_whitelist', function ( $endpoints ) {
$your_endpoints = array(
'/wp-json/wc/v1/disconnect_from_trackship/',
'/wp-json/wc/v1/tracking-webhook/',
'/wp-json/wc/v1/check_ts4wc_installed/',
'/wp-json/wc/v1/ts-update-carrier/',
);
return array_unique( array_merge( $endpoints, $your_endpoints ) );
} );
@trackship
trackship / rename_tracking_page_tab
Last active June 2, 2022 12:31
Rename the products tab label on Tracking page
add_filter( 'tracking_page_tab_label', 'rename_tracking_page_tab' );
function rename_tracking_page_tab( $labels_name ) {
// if you don't want to change all tab's names then you have to add particular tab's label code
$labels_name['tracking_progress_label'] = 'Tracker progress'; // Change the name of the Tracking progress tab label
$labels_name['items_label'] = 'Products in this Shipment'; // Change the name of the Progress tab label
$labels_name['notifications_label'] = 'Shipment status notifications'; // Change the name of the Notifications tab label
return $labels_name;
}
@trackship
trackship / tracking_page
Created May 17, 2022 07:17
To remove the search by Order ID and Order Email section from Tracking Pag
// remove order id and email id section from Tracking page form
add_filter( 'remove_order_id_section', '__return_true' );
@trackship
trackship / delivery-automation.php
Last active March 28, 2023 04:24
Add custom statuses for delivery automation
/*
* add order status to trigger delivered status
*/
add_filter( 'allowed_order_status_for_delivered', 'allow_status_for_delivery_automation' );
function allow_status_for_delivery_automation( $order_statuses ) {
$order_statuses[] = 'in_transit';
$order_statuses[] = 'packed';
$order_statuses[] = 'delivering'; //You can add your custom order statuses like this for delivery automation.
return $order_statuses;
}
@trackship
trackship / trigger_ts_status_change.php
Created January 28, 2022 09:32
Code snippet for send SMS using Twilio SMS Notifications plugin when shipment status has changed from TrackShip
<?php
add_action( 'ast_trigger_ts_status_change', 'ast_send_status_change_sms_twillio', 10, 3 );
function ast_send_status_change_sms_twillio($order_id, $old_status, $new_status){
$wc_ast_api_key = get_option('wc_ast_api_key');
$blog_title = get_bloginfo();
if ( !is_plugin_active( 'woo-advanced-shipment-tracking/woocommerce-advanced-shipment-tracking.php' ) ) {
return;
}
if( !$wc_ast_api_key ){
return;
@trackship
trackship / change-tracking-form-text.php
Created January 28, 2022 09:30
Filter for change text of tracking page
<?php
// Filter for change description before tracking form
// Default text - To track your order please enter your Order ID in the box below and press the "Track" button. This was given to you on your receipt and in the confirmation email you should have received.
add_filter( 'ast_tracking_page_front_text', 'ast_tracking_page_front_text_fun' );
function ast_tracking_page_front_text_fun($string){
$string = 'Updated Text';
return $string;
}
// Filter for change text of order label in form
/**
* Remove text from the tracking events description
*/
add_filter( 'trackship_tracking_event_description', 'remove_text_tracking_event_description', 10, 1 );
function remove_text_tracking_event_description( $message ) {
// add word in below $remove array to remove from tracking event description
$remove = array(
"Mariam", // you can add multiple rows
);
$message = str_replace( $remove, "", $message );