Skip to content

Instantly share code, notes, and snippets.

View jack-arturo's full-sized avatar

Jack Arturo jack-arturo

View GitHub Profile
@jack-arturo
jack-arturo / set-infusionsoft-tracking-cookie.php
Created September 9, 2022 09:43
Sets the Infusionsoft referral partner tracking cookie based on a URL parameter, so it can be passed to a subdomain.
@jack-arturo
jack-arturo / wpf-sync-pending-yith-quotes.php
Created September 6, 2022 12:31
Sync YITH Request A Quote pending orders to ActiveCampaign Deep Data as if they'd already been paid for
<?php
// Sync YITH Request A Quote pending orders to AC as if they'd been paid.
function add_custom_paid_status( $statuses ) {
$statuses[] = 'ywraq-new';
$statuses[] = 'ywraq-pending';
return $statuses;
@jack-arturo
jack-arturo / tag-based-on-username.php
Created July 22, 2022 08:33
When a user registers in WordPress, applies a tag in the CRM with their username
<?php
function tag_based_on_username( $user_id ) {
$user = get_user_by( 'id', $user_id );
wp_fusion()->user->apply_tags( array( $user->user_login ), $user_id );
}
@jack-arturo
jack-arturo / wpf-ac-resubscribe-to-list.php
Created June 2, 2022 13:20
Re-susbscribes an unsubscribed contact to the selected list when their profile is updated
<?php
// This runs whenever WP Fusion updates an existing contact record. It re-subscribes them to the list ID specified.
function re_subscribe_to_list( $args ) {
$list_id = 1; // Update this with your list ID.
$args[1][ 'p[' . $list_id . ']' ] = $list_id;
$args[1][ 'status[' . $list_id . ']' ] = 1;
@jack-arturo
jack-arturo / wpf-multisite-meta-keys.php
Last active November 15, 2021 15:11
Prefix the WPF contact ID and tags meta keys with the current blog prefix
<?php
/**
* When the user's contact ID or tags are saved, prefix the usermeta key with
* the blog prefix of the current blog.
*
* @param bool $check Whether or not to bypass the original database
* check.
* @param int $user_id The user ID.
* @param string $meta_key The meta key.
@jack-arturo
jack-arturo / wpf-track-login-streak.php
Last active September 21, 2021 08:03
Updates a wpf_logins_streak field each time a user logs in on two consecutive days
<?php
function wpf_track_login_streak( $meta_id, $user_id, $meta_key, $meta_value ) {
if ( 'wpf_last_login' === $meta_key ) { // this runs every time the wpf_last_login field is about to be updated.
$prev_value = get_user_meta( $user_id, 'wpf_last_login', true ); // get the previous last login timestamp.
$prev_value = floor( absint( $prev_value ) / DAY_IN_SECONDS ); // Convert to days since Jan 1st 1970.
@jack-arturo
jack-arturo / edd-improved-grandfathered-renewal-discount.php
Last active August 28, 2021 10:47
Easy Digital Downloads grandfathered renewal discounts, with support for upgrades and reactivations
<?php
/**
* Sets renewal discount to 30% for any customer that purchased before January
* 1, 2021.
*
* @param int $renewal_discount The renewal discount.
* @param int $license_id The license ID.
* @return int The renewal discount amount.
*/
function wpf_edd_grandfather_renewal_discount( $renewal_discount, $license_id ) {
@jack-arturo
jack-arturo / wpf-lookup-hubspot-company.php
Created August 4, 2021 14:11
Uses a saved company_id to lookup the company for a HubSpot contact over the Companies API
<?php
function example_hubspot_company_lookup( $user_id ) {
$company_id = get_user_meta( $user_id, 'company_id', true );
$request = 'https://api.hubapi.com/crm/v3/objects/companies/' . $company_id; // see https://developers.hubspot.com/docs/api/crm/companies
$response = wp_remote_get( $request, wp_fusion()->crm->get_params() );
if ( is_wp_error( $response ) ) {
wpf_log( 'error', 0, $response->get_error_message() );
@jack-arturo
jack-arturo / wpf-sync-lifetime-value.php
Created March 17, 2021 08:16
Calculates a WooCommerce lifetime value for registered users when syncing metadata to the CRM
<?php
function example_sync_lifetime_value( $user_meta, $user_id ) {
$user_meta['lifetime_value'] = 0;
$customer_orders = get_posts(
array(
'posts_per_page' => -1,
'post_type' => 'shop_order',
'post_status' => wc_get_is_paid_statuses(),
@jack-arturo
jack-arturo / wpf-tag-count.php
Created March 16, 2021 09:14
Show the number of users with a tag
<?php
//
// Tag Count shortcode, use like [wpf_tag_count tag="Tag Name"]
//
function wpf_tag_count( $atts ) {
$tag = wpf_get_tag_id( $atts['tag'] );
$result = get_transient( 'wpf_tag_count_' . sanitize_key( $tag ) );