Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
Last active September 14, 2022 11:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielbitzer/215b37e7ae25e020c36e3cfcffeab069 to your computer and use it in GitHub Desktop.
Save danielbitzer/215b37e7ae25e020c36e3cfcffeab069 to your computer and use it in GitHub Desktop.
[AutomateWoo] Custom date variable for meta field. More info at https://automatewoo.com/docs/variables/custom-variables/
<?php
add_filter( 'automatewoo/variables', 'my_automatewoo_variables' );
/**
* @param $variables array
* @return array
*/
function my_automatewoo_variables( $variables ) {
$variables['order']['my_custom_date'] = dirname(__FILE__) . '/variable-my-custom-date.php';
return $variables;
}
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* @class My_AW_Variable_Custom_Date
*/
class My_AW_Variable_Custom_Date extends AutomateWoo\Variable_Abstract_Datetime {
protected $name = 'order.custom_date';
function load_admin_details() {
$this->description = __( '...', 'automatewoo');
parent::load_admin_details();
}
/**
* @param $order WC_Order
* @param $parameters array
* @return string|false
*/
function get_value( $order, $parameters ) {
$timestamp = $order->get_meta( '_my_custom_timestamp' );
if ( ! $timestamp ) {
return false;
}
$date = new DateTime();
$date->setTimestamp( $timestamp );
return $this->format_datetime( $date, $parameters );
}
}
return new My_AW_Variable_Custom_Date();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment