Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 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 / 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 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 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();