Skip to content

Instantly share code, notes, and snippets.

View EvanHerman's full-sized avatar
🐈
Cats, Code, WordPress

Evan Herman EvanHerman

🐈
Cats, Code, WordPress
View GitHub Profile
@EvanHerman
EvanHerman / easy-forms-for-mailchimp-email-notifications.php
Last active May 20, 2020 09:10
Easy Forms for MailChimp - Email notifications when a user signs up
<?php
/*
* This snippet should go at the bottom of your functions.php file.
* Send a notification email to the user after a form is successfully submitted
* @sample snippet
*/
function yikes_easy_forms_for_mailchimp_email_notifications( $email, $submitted_data, $form, $notifications ) {
if( ! empty( $submitted_data ) ) {
// add additional items you don't want included in the email notification
$exclude_from_email = array(
@EvanHerman
EvanHerman / unset-default-woocommerce-shipping-methods.php
Last active November 17, 2015 16:42
Remove default shipping methods from the dashboard (doesn't work to unset 'Flat Rate'). Great for cleaning up the shipping settings page and managing what shipping methods are available for site admins to manage.
<?php
/*
* Remove unused shipping rates from the dashboard
* note: WC_Shipping_Flat_Rate does not work here
* Defaults:
* - WC_Shipping_Free_Shipping
* - WC_Shipping_International_Delivery
* - WC_Shipping_Local_Delivery
* - WC_Shipping_Local_Pickup
*/
@EvanHerman
EvanHerman / redirect-user-back-to-product.php
Created November 13, 2015 16:30
WooCommerce - After login, redirect the user back to the last viewed product
<?php
/*
* Add a hidden field to our WooCommerce login form - passing in the refering page URL
* Note: the input (hidden) field doesn't actually get created unless the user was directed
* to this page from a single product page
*/
function redirect_user_back_to_product() {
// check for a referer
$referer = wp_get_referer();
// if there was a referer..
@EvanHerman
EvanHerman / scrollto-element.js
Created November 6, 2015 00:48
jQuery smooth scroll to an element in the dom (without third party plugin)
jQuery( 'html, body' ).animate({
scrollTop: jQuery( "#elementtoScrollToID" ).offset().top
}, 2000);
@EvanHerman
EvanHerman / no-free-shipping-product-categories.php
Last active November 4, 2015 15:32
Disable WooCommerce Free Shipping based on the assigned product category (in this case category with ID #112)
<?php
/**
* Disable free shipping for select WooCommerce product categories
* - In this case, free shipping is disabled when a product has the category with ID 112 assigned to it
* @param bool $is_available
*/
function disable_free_shipping_for_certain_product_categories( $is_available ) {
global $woocommerce;
// set the product ids that are ineligible
@EvanHerman
EvanHerman / populate-field-with-url-param-plugin.php
Last active October 12, 2015 13:52
Easy Forms for MailChimp by YIKES - Pre-populate form field with URL Param shortcode.
<?php
/*
* Add a new custom tag to the 'pre defined tags' section
* @ Change 'tag', 'description' and 'title' to suit your needs.
* @ $available_tags - the default pre-defined tags available out of the box
*/
add_filter( 'yikes-mailchimp-custom-default-value-tags', 'add_new_pre_defined_tags' );
function add_new_pre_defined_tags( $available_tags ) {
// define a new array, with our default tag data (note: to create more than one, simply copy and paste what is below and alter the values)
@EvanHerman
EvanHerman / wp-svg-icon-repair-snippet.php
Created October 9, 2015 12:12
Fix WP SVG Icons being overridden in the dashboard
<?php
/*
* This snippet gets placed at the bottom of your active themes functions.php file
* - This is necessary as some themes load their own set of icons and use !important; which conflicts with our plugin
*/
/*
* Fix theme's overriding the default icon set in the dashboard
*/
@EvanHerman
EvanHerman / acf-file-field-download-after-submission.php
Last active October 8, 2015 17:49
After a form is successfully submitted, redirect the user to a download attached to the current page and assigned to an ACF (http://www.advancedcustomfields.com/) 'file' field.
<?php
/*
* Grab the contents of an ACF 'file' field, called attached_file, on the page the form was submitted on (ie: page with ID 15)
* and re-direct the user to that URL (to download the file) after a successful submission.
* @since 0.1
*/
function yikes_mailchimp_alter_redirect_url( $url, $form_id, $page_data ) {
// grab the ACF field -- returns an array
// (Example: Array ( [id] => 43 [alt] => [title] => 2002 [caption] => [description] => [mime_type] => file/zip [url] => http://www.example.com/file.zip ) )
@EvanHerman
EvanHerman / yikes-easy-forms-for-mailchimp-custom-default-value-tag.php
Last active October 12, 2015 13:40
Add custom tags to the 'pre defined tags' section
<?php
/*
* Add a new custom tag to the 'pre defined tags' section
* @ Change 'tag', 'description' and 'title' to suit your needs.
* @ $available_tags - the default pre-defined tags available out of the box
*/
add_filter( 'yikes-mailchimp-custom-default-value-tags', 'add_new_pre_defined_tags' );
function add_new_pre_defined_tags( $available_tags ) {
// define a new array, with our default tag data (note: to create more than one, simply copy and paste what is below and alter the values)
$available_tags[] = array(
@EvanHerman
EvanHerman / yikes-mailchimp-redirect-url-example.php
Last active October 7, 2015 16:13
Easy Forms for MailChimp - Alter URL user is redirected too using the yikes-mailchimp-redirect-url filter
<?php
/*
* Alter the URL the user is redirected to after a successfull submission of form #3
* - Add a custom URL, or add query args to the page URL selected on the edit forms page
* @parameters
* $url - the original URL set on the edit forms page
* $form_id - the ID of the form that was submitted
* $page_data - the global $post data - contains all sorts of info about the current page (including ID, title etc.)
*/
function yikes_mailchimp_alter_redirect_url( $url, $form_id, $page_data ) {