Skip to content

Instantly share code, notes, and snippets.

View verygoodplugins's full-sized avatar

Very Good Plugins verygoodplugins

View GitHub Profile
@verygoodplugins
verygoodplugins / edd-custom-cancel.php
Created November 1, 2022 09:59
Modifies the Easy Digital Downloads cancellation link to point to a custom "Confirm cancellation" page
<?php
/**
* Modify the EDD cancel URL to point custom cancellation page.
*
* @param string $url The cancel URL.
* @param EDD_Subscription $subscription The subscription.
*/
function wpf_edd_subscription_cancel_url( $url, $subscription ) {
@verygoodplugins
verygoodplugins / 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.
@verygoodplugins
verygoodplugins / 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;
@verygoodplugins
verygoodplugins / 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 );
}
@verygoodplugins
verygoodplugins / 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;
@verygoodplugins
verygoodplugins / wpf-learndash-require-enrolled.php
Created April 21, 2020 08:11
Modifies WP Fusion's course access permissions for LearnDash so users must be enrolled in the course to see the course page
<?php
// Check course access
function check_ld_access( $can_access, $user_id, $post_id ) {
if ( ! function_exists( 'sfwd_lms_has_access' ) ) {
return $can_access;
}
@verygoodplugins
verygoodplugins / wpf-update-custom-object.php
Last active December 29, 2021 11:23
Create / update a custom Event object in Zoho. Salesforce, or HubSpot when an "event" post type is created or updated
<?php
// Runs on any post with post type "event" and updates the "Event" custom object with values Title and EventDate
function create_update_event_object( $post_id, $post, $update ) {
// Don't run if WP Fusion isn't active, otherwise you'll get an error
if ( ! function_exists( 'wp_fusion' ) ) {
return;
@verygoodplugins
verygoodplugins / 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.
@verygoodplugins
verygoodplugins / wpf-sync-multiple-subscription-renewal-dates.php
Last active November 4, 2021 07:20
Allows syncing the renewal dates from multiple WooCommerce subscriptions into multiple custom fields
<?php
function wpf_subscription_products_meta_fields( $fields ) {
if ( ! class_exists( 'WC_Subscriptions_Product' ) ) {
return;
}
$args = array(
'post_type' => 'product',
@verygoodplugins
verygoodplugins / 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.