Skip to content

Instantly share code, notes, and snippets.

View zorem's full-sized avatar

zorem zorem

View GitHub Profile
@zorem
zorem / functions.php
Last active December 27, 2019 12:34
Code for update tracking page text
<?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
@zorem
zorem / functions.php
Last active June 23, 2020 05:24
Code for change tracking provider name in email, my account section and trackship tracking page
<?php
add_filter( 'ast_provider_title', 'ast_provider_title_fun' );
function ast_provider_title_fun($provider){
if($provider == 'UPS')$provider = 'Updated UPS';
return $provider;
}
?>
@zorem
zorem / add-tracking-info-order.php
Last active April 12, 2022 04:33
Add tracking info into orders
<?php
// Check if AST PRO plugin is Installed
if ( class_exists( 'AST_Pro_Actions' ) ) {
$order_id = '123'; //Replace with your order id
$tracking_provider = 'USPS'; //Replace with your shipping provider
$tracking_number = '123123'; //Replace with your tracking number
$date_shipped = '2020-06-22'; ////Replace with your shipped date
$status_shipped = 1; // 0=no,1=shipped,2=partial shipped(if partial shipped order status is enabled)
$sku = 't-shirt,blue-jeans'; //the line item (product) SKU
@zorem
zorem / create_partial_shipped_status.php
Created October 25, 2019 06:03
From this code snippet you can create custom order status partial shipped
<?php
// Add this code to your theme functions.php file or a custom plugin
add_action('init', 'register_partial_shipped_order_status');
//add status after completed
add_filter('wc_order_statuses', 'add_partial_shipped_to_order_statuses');
//Custom Statuses in admin reports
add_filter('woocommerce_reports_order_statuses', 'include_partial_shipped_order_status_to_reports', 20, 1);
// for automate woo to check order is paid
add_filter('woocommerce_order_is_paid_statuses', 'partial_shipped_woocommerce_order_is_paid_statuses');
/*** Register new status : Delivered
@zorem
zorem / ast_trigger_ts_status_change.php
Created November 6, 2019 05:54
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;
@zorem
zorem / functions.php
Last active June 23, 2020 06:35
How to get a tracking details of order for AST and include tracking details in emails
<?php
if ( class_exists( 'WC_Advanced_Shipment_Tracking_Actions' ) ) {
$order_id = 123;
$wc_ast_unclude_tracking_info = get_option('wc_ast_unclude_tracking_info');
$order = wc_get_order( $order_id );
$order_status = $order->get_status();
if ( is_a( $email, 'WC_Email_Customer_Invoice' ) && isset($wc_ast_unclude_tracking_info['show_in_customer_invoice']) && $wc_ast_unclude_tracking_info['show_in_customer_invoice'] == 0){
@zorem
zorem / update_label_order_meta_data.php
Last active August 5, 2020 04:28
WooCommerce Shipping Compatibility - Replace "update_label_order_meta_data" function in "class-wc-connect-service-settings-store.php" file in "classes" folder inside plugin
/*
* status_shipped - (0=no,1=shipped,2=partial shipped(if partial shipped order status is enabled))
*/
public function update_label_order_meta_data( $order_id, $new_label_data ) {
$result = $new_label_data;
$labels_data = $this->get_label_order_meta_data( $order_id );
foreach( $labels_data as $index => $label_data ) {
if ( $label_data['label_id'] === $new_label_data->label_id ) {
$result = array_merge( $label_data, (array) $new_label_data );
$labels_data[ $index ] = $result;
@zorem
zorem / create_custom_order_order_status.php
Created January 2, 2020 10:39
Code snippet for create custom order status
<?php
// Add this code to your theme functions.php file or a custom plugin
add_action('init', 'register_order_status');
//add status after completed
add_filter('wc_order_statuses', 'add_custom_status_to_order_statuses');
//Custom Statuses in admin reports
add_filter('woocommerce_reports_order_statuses', 'include_custom_order_status_to_reports', 20, 1);
// for automate woo to check order is paid
add_filter('woocommerce_order_is_paid_statuses', 'custom_status_woocommerce_order_is_paid_statuses');
/*** Register new status : Delivered
@zorem
zorem / add_tracking_info_per_item.php
Last active September 13, 2021 18:58
Endpoint – Create a shipment tracking per item using REST API
//With this endpoint you can add new tracking info to orders:
POST /wp-json/wc-ast-pro/v3/orders/<order_id>/shipment-trackings/
curl -X POST https://your-domain.com/wp-json/wc-ast-pro/v3/orders/<order_id>/shipment-trackings
-u consumer_key:consumer_secret
-H "Content-Type: application/json"
-d '{
"tracking_provider": "USPS",
"tracking_number": "123456",
@zorem
zorem / get_formatted_tracking_info.php
Last active April 11, 2022 12:49
Below is the code snippet for get formatted tracking info
<?php
// Check if function exist
if ( function_exists( 'ast_get_tracking_items' ) ) {
$order_id = 123; // Replace with your order_id
$tracking_items = ast_get_tracking_items($order_id);
foreach($tracking_items as $tracking_item){
$tracking_number = $tracking_item['tracking_number'];