Skip to content

Instantly share code, notes, and snippets.

@drahcirwalsh
Created August 29, 2025 17:01
Show Gist options
  • Select an option

  • Save drahcirwalsh/bf6db5264ebc78bd3c6093f949246323 to your computer and use it in GitHub Desktop.

Select an option

Save drahcirwalsh/bf6db5264ebc78bd3c6093f949246323 to your computer and use it in GitHub Desktop.
Create custom AutomateWoo Variables to support Magic Login Pro in AutomateWoo Emails
<?php
/**
* Magic Login Pro + AutomateWoo Integration
* Simple file-based variable registration
*
* @package PrintSolutionsAutomation
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Register Magic Login variables with AutomateWoo
*/
add_filter( 'automatewoo/variables', 'psa_register_magic_login_variables' );
/**
* @param array $variables
* @return array
*/
function psa_register_magic_login_variables( $variables ) {
// Only register if both plugins are available
if ( ! class_exists( '\AutomateWoo\Variable' ) || ! function_exists( '\MagicLogin\Utils\create_login_link' ) ) {
return $variables;
}
$base_path = plugin_dir_path( __FILE__ ) . 'automatewoo-variables/';
// Add variables to customer data type
$variables['customer']['magic_login_link'] = $base_path . 'variable-customer-magic-login-link.php';
$variables['customer']['magic_login_qr'] = $base_path . 'variable-customer-magic-login-qr.php';
// Also add to user data type (using same files)
$variables['user']['magic_login_link'] = $base_path . 'variable-customer-magic-login-link.php';
$variables['user']['magic_login_qr'] = $base_path . 'variable-customer-magic-login-qr.php';
return $variables;
}
<?php
/**
* Magic Login QR Code Variable for AutomateWoo
* File-based variable definition
*
* @package PrintSolutionsAutomation
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* @class PSA_Variable_Customer_Magic_Login_QR
*/
class PSA_Variable_Customer_Magic_Login_QR extends \AutomateWoo\Variable {
/**
* Load admin details
*/
public function load_admin_details() {
$this->description = __( 'Generates a QR code image URL for the magic login link.', 'print-solutions-automation' );
}
/**
* Get the value
*
* @param \AutomateWoo\Customer $customer
* @param array $parameters
* @param \AutomateWoo\Workflow $workflow
* @return string
*/
public function get_value( $customer, $parameters, $workflow ) {
// Check if Magic Login functions exist
if ( ! function_exists( '\MagicLogin\Utils\create_login_link' ) || ! class_exists( '\MagicLogin\QR' ) ) {
return '';
}
// Get the user from the customer
$user = $customer->get_user();
// If no user, try to get by email
if ( ! $user ) {
$email = $customer->get_email();
if ( $email ) {
$user = get_user_by( 'email', $email );
}
}
// No user found
if ( ! $user || ! is_a( $user, 'WP_User' ) ) {
return '';
}
// Generate the magic login link
$link = \MagicLogin\Utils\create_login_link( $user );
if ( ! $link ) {
return '';
}
// Generate QR code URL
$qr_src = \MagicLogin\QR::get_image_src( $link );
return $qr_src ? esc_url( $qr_src ) : '';
}
}
// Return the variable instance
return new PSA_Variable_Customer_Magic_Login_QR();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment