Skip to content

Instantly share code, notes, and snippets.

View scottopolis's full-sized avatar

Scott Bolinger scottopolis

View GitHub Profile
@scottopolis
scottopolis / apppresser-admob-interstitial.js
Last active June 14, 2021 08:10
Sample Javascript to show an interstitial ad in an AppPresser app
// https://docs.apppresser.com/article/515-interstitial-ads
(function() {
// show an interstitial when an element with an id of showAd is clicked. For example, add this to your app:
// <button ion-item id="showAd" (click)="pushPage( pages.tab_menu.items[1] )"><ion-icon name="cog" item-left></ion-icon>Show ad and navigate</button>
// you can use any element with the id of showAd, it doesn't have to be a button
// you can also load the interstitial when the app loads by moving it outside the ready function
ready("#showAd", function(element) {
var el = document.getElementById("showAd");
@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 / 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 / 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 / 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 / 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;
@scottopolis
scottopolis / appcommunity-user-profile-data.php
Last active January 27, 2021 18:45
Add User Profile Data in AppCommunity
<?php
// add this code to a custom plugin
add_filter('appcommunity_prepare_user', function( $data, $request ) {
// $data['id'] is the user_id. With that, you can look up user meta like this
// $data['appp']['below_content'] = '<p>Welcome back ' . get_user_meta( $data['id'], 'nickname', 1 ) . '!</p>';
// you can also show xprofile fields like this
$data['appp']['user_actions'] = '<div class="custom-profile-fields"><p><strong>' . xprofile_get_field( 1, $data['id'] )->name . '</strong><br/>' . xprofile_get_field_data( 1, $data['id'] ) . '</p><p><strong>' . xprofile_get_field( 2, $data['id'] )->name . '</strong><br/>' . xprofile_get_field_data( 2, $data['id'] ) . '</p></div>';
@scottopolis
scottopolis / apppresser-learndash-content.php
Last active January 10, 2021 19:02
Custom LearnDash Content for AppPresser
<?php
/*
* Add custom content (such as a video) before the LearnDash content
* This example adds a video from BuddyBoss to the app
* Add this code to a plugin, change the post meta value as necessary
*/
add_filter("learndash_content", function($content, $post) {
if( class_exists('AppPresser') && AppPresser::is_app() ) {