Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
danielbitzer / functions.php
Created March 7, 2018 19:40
AutomateWoo - Add attachment to workflow email
<?php
add_filter( 'automatewoo/workflow/mailer', 'my_add_attachment_to_workflow_emails', 10, 2 );
/**
* @param Mailer $mailer
* @param Workflow_Email $workflow_email
* @return Mailer
*/
function my_add_attachment_to_workflow_emails( $mailer, $workflow_email ) {
@danielbitzer
danielbitzer / functions.php
Last active June 8, 2023 12:42
Copy the WooCommerce order billing address to user profile when profile email is blank
<?php
add_action( 'woocommerce_checkout_order_processed', 'my_woocommerce_copy_billing_email_to_user_profile', 10, 3 );
/**
* Copy the order billing address to user profile when profile email is blank.
*
* Requires WooCommerce 3.0
*
* @param $order_id
@danielbitzer
danielbitzer / functions.php
Last active June 8, 2023 12:42
Customizing WooCommerce and AutomateWoo email CSS with a filter
<?php
add_filter( 'woocommerce_email_styles', 'my_filter_woocommerce_email_styles' );
/**
* Filter email styles for WooCommerce and AutomateWoo.
*
* @param string $css
*
* @return string
@danielbitzer
danielbitzer / file.php
Last active May 18, 2023 15:31
AutomateWoo - Action function to change subscription next payment date
<?php
/**
* AutomateWoo action function to extend a subscription by 3 months.
*
* A note will be added to the subscription.
*
* Ensures that the dates near the end of the month are logically handled and do not shift to the start of the following month.
*
* Custom action function docs: https://automatewoo.com/docs/actions/custom-functions/
*
@danielbitzer
danielbitzer / functions.php
Last active May 18, 2023 15:31
Add product images to WooCommerce order emails, also adds images to AutomateWoo order table
<?php
/**
* Add product images to the WooCommerce order table used in HTML emails.
*/
add_filter( 'woocommerce_email_order_items_args', function( $args ) {
$args['show_image'] = true;
$args['image_size'] = array( 100, 100 );
return $args;
}, 10, 1 );
@danielbitzer
danielbitzer / functions.php
Last active January 22, 2023 21:39
AutomateWoo - Async custom trigger example
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Register AutomateWoo triggers.
add_filter( 'automatewoo/triggers', function ( $triggers ) {
// Include the file containing the trigger class
require_once 'my-custom-order-paid-trigger.php';
@danielbitzer
danielbitzer / class-custom-trigger.php
Last active December 15, 2022 22:29
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 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 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 / 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();