Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:32
AutomateWoo Custom Validation Example
<?php
add_filter( 'automatewoo_custom_validate_workflow', 'my_custom_workflow_validation' );
/**
* @param bool $valid
* @param AW_Model_Workflow $workflow
*
* @return bool
*/
@danielbitzer
danielbitzer / class-custom-trigger.php
Last active August 26, 2024 15:25
AutomateWoo Custom Trigger Example
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Prevent direct access
}
/**
* This is an example trigger that is triggered via a WordPress action and includes a user data item.
* Trigger with: do_action('my_custom_action', $user_id );
*/
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:31
AutomateWoo - Filtering the value of a variable
<?php
/**
* An example of how to filtering the value of a variable
*
* In this example we will format user first and last names.
*/
add_filter( 'automatewoo/variables/after_get_value', 'my_automatewoo_variable_filter_names', 10, 5 );
/**
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:30
[AutomateWoo] Display text dynamically based on the number of items in an order. More info at https://automatewoo.com/docs/variables/custom-variables/
<?php
/**
* Add the custom variable to the list
*/
add_filter( 'automatewoo/variables', 'my_automatewoo_variables' );
/**
* @param $variables array
* @return array
*/
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:30
Custom AutomateWoo Rules
<?php
add_filter('automatewoo/rules/includes', 'my_automatewoo_rules' );
/**
* @param array $rules
* @return array
*/
function my_automatewoo_rules( $rules ) {
@danielbitzer
danielbitzer / import-referral-coupons.php
Created October 25, 2016 23:54
Import referral coupons script
<?php
foreach( $users as $user_id )
{
// fetch the existing key
// please note that the key should NOT include the referral prefix
// so if your prefix is 'REF' then the final coupon here will be 'REF1234'
$key = '1234'
$object = new AW_Model_Referral_Advocate_Key();
@danielbitzer
danielbitzer / functions.php
Last active December 5, 2022 06:58
[AutomateWoo] Setting custom guest capture selectors. More info at https://automatewoo.com/docs/abandoned-cart/
<?php
add_filter( 'automatewoo/guest_capture_fields', 'my_guest_capture_fields' );
/**
* @param array $selectors
*/
function my_guest_capture_fields( $selectors ) {
$selectors[] = '#example-id-selector';
$selectors[] = '.example-class-selector';
@danielbitzer
danielbitzer / functions.php
Last active April 29, 2024 13:32
AutomateWoo Refer A Friend - Make referral coupons use the user ID of the advocate instead of a random string
<?php
// In addition to adding this code you should set the Coupon Expiry setting to zero to disable coupon expiry
add_filter('automatewoo/referrals/generate_advocate_key', 'my_automatewoo_referrals_generate_advocate_key', 10, 2 );
/**
* @param $key
* @param AW_Model_Referral_Advocate $advocate
* @return int|string
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:29
Restrict referral coupons by product ID
<?php
add_filter('automatewoo/referrals/coupon_data', 'my_automatewoo_referrals_coupon_data' );
/**
* Restrict referral coupon to product IDs
*
* @param array $coupon_data
* @return array
*/
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:29
[Refer A Friend] Custom validation for referral coupons - Restrict coupon use to advocates with active subscriptions
<?php
add_filter( 'automatewoo/referrals/validate_coupon_for_user', 'my_automatewoo_referral_coupon_validate', 10, 3 );
add_filter( 'automatewoo/referrals/validate_coupon_for_guest', 'my_automatewoo_referral_coupon_validate', 10, 3 );
/**
* $valid is true if coupon is valid for user or an instance of WP_Error if the coupon is invalid
*
* @param WP_Error|true $valid