Last active
September 14, 2022 11:18
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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