Last active
September 14, 2022 11:26
-
-
Save danielbitzer/ffac7d68192c8a007af1926ef8431dd5 to your computer and use it in GitHub Desktop.
[AutomateWoo] Custom variable - Order delivery date for Tyche Softwares plugin
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']['delivery_date'] = dirname(__FILE__) . '/variable-order-delivery-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_Order_Delivery_Date | |
*/ | |
class My_AW_Variable_Order_Delivery_Date extends AutomateWoo\Variable_Abstract_Datetime { | |
protected $name = 'order.delivery_date'; | |
function init() { | |
$this->description = __( 'Displays the delivery date for the order.', 'automatewoo'); | |
$this->add_parameter_text_field( 'time', 'Time of day, use 24 hour time', false, 'HH:MM' ); | |
parent::init(); | |
} | |
/** | |
* @param $order WC_Order | |
* @param $parameters array | |
* @return string|false | |
*/ | |
function get_value( $order, $parameters ) { | |
$timestamp = AutomateWoo\Compat\Order::get_meta( $order, '_orddd_timestamp' ); | |
if ( ! $timestamp ) { | |
return false; | |
} | |
$date = new DateTime(); | |
$date->setTimestamp( $timestamp ); | |
if ( ! empty( $parameters['time'] ) ) { | |
$parts = explode( ':', wc_clean( $parameters['time'] ) ); | |
if ( count( $parts) !== 2 ) { | |
return false; | |
} | |
$date->setTime( (int) $parts[0], (int) $parts[1], 0 ); | |
} | |
return $this->format_datetime( $date, $parameters ); | |
} | |
} | |
return new My_AW_Variable_Order_Delivery_Date(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment