Skip to content

Instantly share code, notes, and snippets.

View zorem's full-sized avatar

zorem zorem

View GitHub Profile
@zorem
zorem / wc-customer-my-custom-status-order.php
Last active October 9, 2020 09:42
The plain template will go into templates/emails/plain. We will use the same file name wc-customer-my-custom-status-order.php.
<?php
/**
* Completed Order sent to Customer
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
echo "= " . $email_heading . " =\n\n";
@zorem
zorem / wc-customer-delivered-status-order.php
Last active January 28, 2021 11:06
The last thing is to define the templates that are going to be used for creating the email content. The first template will be an HTML template. Create a file wc-customer-my-custom-status-order.php inside templates/emails/.
<?php
/**
* Completed Order sent to Customer.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
@zorem
zorem / class-wc-delivered-status-order.php
Last active January 28, 2021 11:05
Create a file class-wc-custom-completed-order.php inside the folder "emails" and put below code in it.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WC_Email' ) ) {
return;
}
/**
@zorem
zorem / delivered_wc_email.php
Last active January 28, 2021 11:02
This is where we will hook into the WooCommerce emails and define the absolute path to the theme folder.
<?php
/**
* Class My_Custom_Status_WC_Email
*/
class Delivered_WC_Email {
/**
* Delivered_WC_Email constructor.
*/
public function __construct() {
@zorem
zorem / woocommerce_order_is_paid_statuse.php
Last active October 9, 2020 09:20
The function is going to add this new custom order status as paid statuses.
<?php
add_filter('woocommerce_order_is_paid_statuses', 'custom_status_woocommerce_order_is_paid_statuses');
function custom_status_woocommerce_order_is_paid_statuses($statuses)
{
$statuses[] = 'my-custom-status';
return $statuses;
}
@zorem
zorem / woocommerce_reports_order_statuses.php
Last active October 9, 2020 13:02
The function is going to add this new custom order status to Orders reports.
<?php
add_filter('woocommerce_reports_order_statuses', 'include_custom_order_status_to_reports', 20, 1);
function include_custom_order_status_to_reports($statuses)
{
// Replace 'my-custom-status' with your custom order status slug
if ($statuses)
$statuses[] = 'my-custom-status';
return $statuses;
}
@zorem
zorem / add_custom_completed_status_to_order_statuses.php
Last active October 9, 2020 13:02
The function is going to add this new custom post status into the list of available order statuses within the WooCommerce “Orders” and “Edit Orders” pages so that we can actually use it. We want to pass in the current order statuses so that we can go through them and insert our order status into the list where we’d like it.
<?php
add_filter('wc_order_statuses', 'add_custom_status_to_order_statuses');
function add_custom_status_to_order_statuses($order_statuses)
{
// Replace 'my-custom-status' with your custom order status slug
// Replace 'My Custom Status' with your custom order status name
$new_order_statuses = array();
foreach ($order_statuses as $key => $status) {
$new_order_statuses[$key] = $status;
if ('wc-completed' === $key) {
@zorem
zorem / register_completed_order_status.php
Last active October 16, 2020 09:08
Code snippet for creating custom order status
<?php
/*
* This function is registering our custom status as a post status in WordPress.
*/
add_action('init', 'register_custom_order_status');
function register_custom_order_status()
{
register_post_status('wc-my-custom-status', array( // Replace 'my-custom-status' with your custom order status slug
'label' => __('My Custom Status', 'text-domain'), // Replace 'My Custom Status' with your custom order status name
'public' => true,
@zorem
zorem / rename-order-status.php
Last active May 27, 2021 17:10
Renaming WooCommerce Order Status
<?php
add_filter( 'wc_order_statuses', 'wc_renaming_order_status' );
/*
* Rename WooCommerce Order Status
*/
function wc_renaming_order_status( $order_statuses ) {
foreach ( $order_statuses as $key => $status ) {
$new_order_statuses[ $key ] = $status;
@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'];