Skip to content

Instantly share code, notes, and snippets.

View scottopolis's full-sized avatar

Scott Bolinger scottopolis

View GitHub Profile
@scottopolis
scottopolis / apppresser-iap-indeed.php
Created March 1, 2022 17:16
AppPresser IAP Indeed Memberships
<?php
/*
Plugin Name: AppPresser In App Purchases for Indeed Memberships
Plugin URI: https://apppresser.com
Description: This plugin listens for in app purchases or cancellations and adds/removes members from a membership level.
Version: 1.0.0
Author: Scott Bolinger
Author URI: https://apppresser.com
License: GPLv2
*/
@scottopolis
scottopolis / react-state-object-property.js
Created December 2, 2021 17:31
React set state for object property (one-liner)
// to update a property in an object, for example a title
setMyState({
...currentState,
title: newTitle,
});
/* Explanation below...
// we have an object set as state
@scottopolis
scottopolis / appcommunity-member-list-filter.php
Created June 1, 2021 14:14
AppCommunity member list filter
<?php
// Add groups to member list
// add this code to a custom plugin
function app_extend_bp_member($response, $request, $user) {
$joined_groups = array();
$group_ids = groups_get_user_groups($user->ID);
foreach($group_ids['groups'] as $id) {
$current_group = groups_get_group(array('group_id' => $id));
if($current_group->name !== 'hidden') {
$joined_groups[] = $current_group->name;
@scottopolis
scottopolis / ga-track-outbound.js
Last active January 4, 2024 21:14
Google Analytics track all outbound links with no markup change
// listen for all clicks on anything. You could change document to a selector like #content to make it more efficient.
$(document).on('click', function( e ) {
// if this is a link, and the href does not contain our domain, it's an external link. Track it.
if( e.target.href && e.target.href.indexOf( window.location.hostname ) < 0 ) {
ga('send', 'event', {
eventCategory: 'Outbound Link',
eventAction: 'click',
eventLabel: e.target.href, // the outbound link url will appear as the event label in GA. Find under Behavior -> Events -> Event Label
transport: 'beacon' // not supported in some versions of IE
});
@scottopolis
scottopolis / woo-abandoned-checkout-mailchimp.php
Last active March 16, 2021 16:16
WooCommerce Abandoned Checkout Flow with MailChimp
<?php
// Add this code to a custom plugin on your site to add customer emails to your abandoned checkout flow
// Requires the free plugin code here: https://hollerwp.com/woo-checkout-save-email/
// You need to install this first: composer require drewm/mailchimp-api
// see https://github.com/drewm/mailchimp-api
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('abc123abc123abc123abc123abc123-us1'); // change this to your MC API key
// this action fires when a new email is added to your checkout
@scottopolis
scottopolis / woo-checkout-email-first.php
Created March 11, 2021 16:02
Email First in WooCommerce Checkout
<?php
// make email the first field on the WooCommerce checkout page
add_filter( 'woocommerce_checkout_fields', 'sb_edit_checkout_fields' );
function sb_edit_checkout_fields( $fields ) {
// make email first
$fields['billing']['billing_email']['priority'] = 4;
return $fields;
@scottopolis
scottopolis / woocommerce-add-shipping-phone.php
Created March 8, 2021 17:48
WooCommerce add shipping phone number
<?php
// add this code to a theme functions.php or custom plugin
add_filter( 'woocommerce_checkout_fields' , 'sb_override_checkout_fields' );
// Our hooked in function - $fields is passed via the filter!
function sb_override_checkout_fields( $fields ) {
$fields['shipping']['shipping_phone'] = array(
'label' => __('Phone', 'woocommerce'),
'placeholder'=> _x('Phone', 'placeholder', 'woocommerce'),
@scottopolis
scottopolis / remove-woocommerce-checkout-fields.php
Last active March 11, 2021 15:39
Remove WooCommerce Company, Order Notes, Phone, and Address 2 Fields
<?php
// put this code in your theme functions.php or a custom plugin
add_filter( 'woocommerce_checkout_fields' , 'sb_remove_woo_checkout_fields' );
function sb_remove_woo_checkout_fields( $fields ) {
// remove some billing fields
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_2']);
@scottopolis
scottopolis / appcommerce-attribute-swatches.php
Created March 1, 2021 19:01
AppCommerce Attribute Swatches
<?php
// Support Variation Swatches for WooCommerce plugin in AppPresser
// put this code in a custom plugin
add_filter( 'appcommerce_attribute_terms', function( $terms ) {
foreach( $terms as $key => $option) :
// if you have a different plugin, just replace 'product_attribute_color' with the key from your plugin
$terms[$key]->attribute_color = get_term_meta( $option->term_id, 'product_attribute_color', 1 );
$terms[$key]->attribute_image = wp_get_attachment_url( get_term_meta( $option->term_id, 'product_attribute_image', 1 ) );
endforeach;
@scottopolis
scottopolis / buddypress-api-member-filter.php
Last active February 25, 2021 18:54
Filter BuddyPress API Members
<?php
// add this code to a custom plugin
add_filter('bp_rest_members_get_items_query_args', function( $args, $request ) {
// These are just examples. Find available arguments here: https://codex.buddypress.org/developer/bp_user_query/
$args['search_terms'] = 'football';
$args['exclude'] = '1,2,3';
return $args;