Skip to content

Instantly share code, notes, and snippets.

@trackship
trackship / exclude-klaviyo-phone.php
Created September 6, 2024 11:03
To exclude phone number from Klaviyo webhook
<?php
// Filter to exclude phone number in the Klaviyo Webhook.
add_filter('exclude_klaviyo_phone', 'klaviyo_phone_number' );
function klaviyo_phone_number( $bool ){
$bool = true;
return $bool;
}
@trackship
trackship / disable-notifications.php
Created September 6, 2024 09:40
disable shipment status notifications for specific customer or email addresses or order
<?php
// Hook into the custom action 'ts_status_change_trigger' to trigger our callback function when the Shipment status changes.
add_action('ts_status_change_trigger', 'status_change_callback', 8, 4 );
// Define the callback function that is triggered when the action fires.
function status_change_callback( $order_id, $old_status, $new_status, $tracking_number ) {
// Fetch the WooCommerce order object using the provided order ID.
$order = wc_get_order( $order_id );
@trackship
trackship / estimated-delivery-date-format.php
Created May 7, 2024 12:41
Customize Estimated Delivery Date Format
<?php
// This line adds a filter to modify the estimated delivery date format.
add_filter( 'est_delivery_date_format', 'est_delivery_date_format_callback' );
// This is the callback function that will be triggered when the filter 'est_delivery_date_format' is applied.
function est_delivery_date_format_callback( $date_format ) {
$custom_date_format = 'l, M d, Y'; // Define a custom date format here.
return $custom_date_format; // Return the custom date format. This will be used to format the estimated delivery date.
}
@trackship
trackship / exception-admin-email.php
Created December 28, 2023 10:34
send immediate emails on exception to only admin
<?php
// This code snippet adds a filter to control email recipients for a specific status.
// Use the 'add_multiple_emails_to_shipment_email' filter hook to modify recipient email addresses.
add_filter( 'add_multiple_emails_to_shipment_email', 'add_email_address', 10, 2 );
function add_email_address( $email_to, $new_status ) {
// Check if the status is 'exception' to determine whether to send the email to the admin only.
if ( 'exception' == $new_status ) {
// Override the recipient email array to send the exception email to the admin.
$email_to = ['info@youstore.com']; // Replace with the admin's email address.
@trackship
trackship / shipment-status-email.php
Last active October 28, 2025 13:38
Send Admin a Copy of Shipment Status Email Notification in WooCommerce
<?php
// This code snippet ensures that whenever a customer is notified about a shipment status change (e.g., "Return to Sender"), a copy of the same notification is also sent to the store admin (or multiple email addresses). You can customize the status and email addresses to suit your store's needs.
// Customize the shipment status and admin email addresses as needed.
add_filter( 'add_multiple_emails_to_shipment_email', 'customize_email_recipients', 10, 2 );
function customize_email_recipients( $email_to, $new_status ) {
// Replace 'return_to_sender' with the desired status to trigger the admin email notification.
if ( 'return_to_sender' == $new_status ) {
$email_to[] = 'info@yourstore.com'; // Add admin recipients here.
// Example: $email_to[] = 'support@yourstore.com';
@trackship
trackship / klaviyo_integration.php
Last active June 9, 2023 13:04
Klaviyo Integration
<?php
/**
* Add Schedule action for Klaviyo intergration when Shipment status change
*/
add_action( 'trackship_shipment_status_trigger', 'ts_status_change_callback', 10, 4 );
function ts_status_change_callback ( $order_id, $old_status, $new_status, $tracking_number ) {
$timestamp = time() + 3;
$hook = 'klaviyo_hoook';
$args = array(
'order_id' => $order_id,
@trackship
trackship / Remove_texts_from_tracking_events.php
Created January 31, 2023 09:26
Remove texts from the tracking events
<?php
add_filter( 'trackship_tracking_event', 'remove_text_tracking_event', 10, 1 );
/**
* Remove specified text in the tracking event.
*
* @param string $tracking_event The tracking event
*
* @return string The modified tracking event
*/
@trackship
trackship / Replace_texts_from_tracking_events.php
Created January 31, 2023 07:26
Replace texts from the tracking events
<?php
add_filter( 'trackship_tracking_event', 'replace_text_tracking_event', 10, 1 );
/**
* Replaces specified text in the tracking event.
*
* @param string $tracking_event The tracking event
*
* @return string The modified tracking event
*/
@trackship
trackship / change_order_status_based_on_shipment_status_change.php
Last active January 7, 2025 07:18
To change order status on change Shipment status.
<?php
/**
*
* To modify the order status of a WooCommerce order in response to a shipment status change,
* you’ll also need to introduce a custom order status for automated delivery processing. To achieve this,
* insert the following code snippet into the functions.php file of your currently active WordPress theme.
* Available shipment statuses slug: 'in_transit', 'available_for_pickup', 'out_for_delivery', 'failure', 'on_hold', 'exception', 'return_to_sender', 'delivered'
*
*/
add_action( 'ts_status_change_trigger', 'ts_status_change_trigger', 10, 4 );
@trackship
trackship / add_email_to_shipment_email.php
Created January 16, 2023 06:41
Add multiple email address to shipment email
<?php
// Add email address for Shipment email will be sent to multiple email address.
add_filter( 'add_multiple_emails_to_shipment_email', 'add_email_address' );
function add_email_address( $email_to ) {
$email_to[] = '{admin_email}'; // Email will be sent to Store admin.
$email_to[] = 'info@youstore.com';
return $email_to;
}