Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Bitzer danielbitzer

View GitHub Profile
@danielbitzer
danielbitzer / functions.php
Last active Apr 8, 2021
Function to programmatically run a specific workflow for a specific order
View functions.php
<?php
/**
* Run a specific workflow for a specific order.
*
* @param int $workflow_id
* @param int $order_id
*
* @throws \Exception
*/
@danielbitzer
danielbitzer / functions.php
Created Jan 6, 2021
AutomateWoo: Make generated coupon descriptions match the template coupon
View functions.php
<?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 Jun 11, 2020
Add product images to WooCommerce order emails, also adds images to AutomateWoo order table
View functions.php
<?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 Apr 23, 2020
AutomateWoo - Custom Date Rule Example
View delivery-date-rule.php
<?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 3, 2021
AutomateWoo - Action function to change subscription next payment date
View file.php
<?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 Apr 14, 2020
AutomateWoo - Async custom trigger example
View functions.php
<?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 Aug 1, 2019
[Refer A Friend] Add customer's referral coupon to order objects returned from REST API
View functions.php
<?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 May 20, 2019
Copy the WooCommerce order billing address to user profile when profile email is blank
View functions.php
<?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 Oct 15, 2020
[Refer A Friend] Make referral coupons into free-gift coupons
View functions.php
<?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 Apr 10, 2019
[Refer A Friend] Programatically get a user's referral coupon/link
View file.php
<?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();