Skip to content

Instantly share code, notes, and snippets.

@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 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 / 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
@danielbitzer
danielbitzer / functions.php
Created January 10, 2017 04:41
[Refer A Friend] Dynamic email from name for referral invites, personalize with the advocate's name
<?php
add_filter('automatewoo/referrals/invite_email/mailer', 'my_filter_referrals_invite_email', 10, 2 );
/**
* @param AW_Mailer $mailer
* @param AW_Referrals_Referral_Invite_Email $invite
* @return AW_Mailer
*/
function my_filter_referrals_invite_email( $mailer, $invite ) {
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:28
[Refer A Friend] Advocate rewards based on their user role and percentage of order
<?php
add_filter( 'automatewoo/referrals/reward_amount', 'my_automatewoo_referral_reward_amount', 10, 3 );
/**
* @param $reward_amount
* @param AW_Model_Referral_Advocate $advocate
* @param WC_Order $order
* @return mixed
*/
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:27
AutomateWoo - Set which order to use for email previews
<?php
add_filter( 'automatewoo/preview_data_layer', 'my_filter_automatewoo_preview_data_layer' );
/**
* @param array $data
* @return array
*/
function my_filter_automatewoo_preview_data_layer( $data ) {
@danielbitzer
danielbitzer / functions.php
Created March 10, 2017 01:53
AutomateWoo - Hide the admin menu from store managers
<?php
add_action( 'admin_menu', 'my_maybe_remove_automatewoo_from_admin_menu', 5 );
function my_maybe_remove_automatewoo_from_admin_menu() {
if ( ! current_user_can( 'administrator' ) ) {
remove_action( 'admin_menu', [ 'AutomateWoo\Admin', 'admin_menu' ] );
}
}