Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
danielbitzer / functions.php
Created December 15, 2017 11:08
AutomateWoo - Set custom reply to for workflow emails
<?php
/**
* @since 3.4.3
*/
add_filter( 'automatewoo/workflow/mailer', 'my_filter_automatewoo_workflow_mailer' );
/**
* @param AutomateWoo\Mailer $mailer
* @return AutomateWoo\Mailer
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:04
Function to programmatically run a specific workflow for a specific order
<?php
/**
* Run a specific workflow for a specific order.
*
* @param int $workflow_id
* @param int $order_id
*
* @throws \Exception
*/
@danielbitzer
danielbitzer / functions.php
Created January 6, 2021 06:27
AutomateWoo: Make generated coupon descriptions match the template coupon
<?php
/**
* AutomateWoo: Make generated coupon descriptions match the template coupon.
*
* Requires AutomateWoo 5.2.
*/
add_action(
'automatewoo/coupon_generator/generate_from_template_coupon',
function ( $coupon, $template_coupon ) {
@danielbitzer
danielbitzer / delivery-date-rule.php
Last active September 14, 2022 11:08
AutomateWoo - Custom Date Rule Example
<?php
defined( 'ABSPATH' ) || exit;
/**
* Custom Rule: Order - Delivery Date
*
* This is an example of creating a custom date rule that uses a meta field as the date value.
* By extending the AutomateWoo\Rules\Abstract_Date class we can use the existing date comparison types with this custom rule.
* For more about date-based rules see: https://automatewoo.com/docs/rules/date-based-rules/
@danielbitzer
danielbitzer / functions.php
Created August 1, 2019 07:23
[Refer A Friend] Add customer's referral coupon to order objects returned from REST API
<?php
add_filter( 'woocommerce_rest_prepare_shop_order_object', 'my_automatewoo_referrals_add_advocate_coupon_to_order_api', 10, 3 );
/**
* AutomateWoo Refer A Friend - Add customer's referral coupon to order objects returned from REST API
*
* Because guest customers can't be advocates only orders by registered users will have the code added.
*
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:12
[Refer A Friend] Make referral coupons into free-gift coupons
<?php
add_filter( 'automatewoo/referrals/coupon_data', 'my_automatewoo_referrals_free_gift_coupon_data', 10, 4 );
/**
* Make AutomateWoo Refer A Friend coupons free gift coupons.
*
* REQUIRES: WooCommerce v3.6 and Refer A Friend v2.3.1
* REQUIRES: https://woocommerce.com/products/free-gift-coupons/
*
@danielbitzer
danielbitzer / file.php
Last active September 14, 2022 11:12
[Refer A Friend] Programatically get a user's referral coupon/link
<?php
$user_id = 1;
$advocate = \AutomateWoo\Referrals\Advocate_Factory::get( $user_id );
// Retrieve or generate a shareable referral coupon (coupon sharing only)
$advocate->get_shareable_coupon();
// Retrieve or generate a shareable referral link (link sharing only)
$advocate->get_shareable_link();
@danielbitzer
danielbitzer / functions.php
Created December 10, 2018 16:35
[AutomateWoo] Prevent email capture and session tracking from the comment form
<?php
// Prevent email capture and session tracking from the comment form
add_action( 'automatewoo_loaded', function() {
remove_action( 'comment_post', [ 'AutomateWoo\Session_Tracker', 'capture_from_comment' ] );
});
@danielbitzer
danielbitzer / functions.php
Last active September 14, 2022 11:13
[AutomateWoo] Update a queued workflow run date programatically
<?php
// Requires AW 4.3
// create date object
$date = new AutomateWoo\DateTime( '2018-07-23 06:12:04' );
// get the queued event by ID
$event = AutomateWoo\Queued_Event_Factory::get( $event_id );
$event->set_date_due( $date );
@danielbitzer
danielbitzer / functions.php
Created July 9, 2018 04:49
[AutomateWoo] Custom session tracking cookies permitted logic
<?php
/**
* Using this filter will completely override the value of 'Require cookie consent' in settings.
* Presubmit tracking is depending on session tracking so this filter will also control when presubmit tracking is permitted
* (unless presubmit tracking is completely disabled in settings).
*/
add_filter( 'automatewoo/session_tracking/cookies_permitted', 'my_filter_automatewoo_session_tracking_cookies_permitted' );
/**