Skip to content

Instantly share code, notes, and snippets.

@vanpariyar
Created December 17, 2020 05:03
Show Gist options
  • Save vanpariyar/2a62002e07bf4428ffd3824cd6e31b23 to your computer and use it in GitHub Desktop.
Save vanpariyar/2a62002e07bf4428ffd3824cd6e31b23 to your computer and use it in GitHub Desktop.
How To make custom variables for the Automate woo
<?php
add_filter( 'automatewoo/variables', 'automatewoo_custom_variable' );
function automatewoo_custom_variable( $variables ) {
/**
* Add Path of the file create folder in the theme file and see below file location.
*/
$variables['order']['veriable_name'] = require_once get_theme_file_path().'/automatewoo/includes/variables/order-variable-name.php';
return $variables;
}
<?php
class AutomateWooPayfastTokenVariable extends AutomateWoo\Variable {
protected $name = 'order.custom_variable';
public $use_fallback = false;
function load_admin_details() {
$this->description = __( 'Genenrate a custom variable', 'automatewoo');
parent::load_admin_details();
}
/**
* @param $order WC_Order
* @param $parameters array
* @return string|false
*/
public function get_value( $order, $parameters ) {
$custom_meta_value = get_post_meta($order->get_id(), '_custom_meta_key', true);
if ( empty( $custom_meta_value ) ) {
return false;
}
return $custom_meta_value;
}
}
return new AutomateWooPayfastTokenVariable();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment