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 / 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 / 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 / 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 / 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 / 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 / Remove-stats-admin-widget.php
Last active December 1, 2015 14:11
Remove Easy Forms for MailChimp dashboard widgets for everyone but admins.
<?php
// when copying, do not include lines 1 & 2
// Create the function to use in the action hook
function yikes_remove_stats_dashboard_widget() {
// Check user capabilities
if( ! current_user_can( 'manage_options' ) ) {
// Remove the stats metabox
remove_meta_box( 'yikes_easy_mc_list_stats_widget', 'dashboard', 'normal' );
// Remove the list activity metabox
@EvanHerman
EvanHerman / enable-sorting-custom-taxonomies.php
Last active April 2, 2017 12:13
Enable taxonomy sorting (tax_position) for custom taxonomies
<?php
/*
* If you've registered a custom taxonomy to assign to one of your custom post types,
* you'll want to add an additional paprameter to the $args array
*
*/
// Register Custom Taxonomy
function custom_taxonomy() {
@EvanHerman
EvanHerman / enable-sorting-default-wp-taxonomies.php
Created December 11, 2015 19:39
Enable taxonomy sorting (tax_position) for default WordPress taxonomies (post - categories etc.)
<?php
/*
* Enable drag & drop sorting on default WordPress taxonomies (ie: categories) - (page/post)
*/
add_filter( 'register_taxonomy_args' , 'add_tax_position_support', 9999, 3 );
function add_tax_position_support( $args, $taxonomy, $object_type ) {
if( 'category' == $taxonomy ) {
$args['tax_position'] = true;
}
@EvanHerman
EvanHerman / create-admin-user.php
Created December 23, 2015 14:44
Programatically create an admin user (WordPress)
<?php
add_action('init', 'prefix_add_user');
function prefix_add_user() {
$username = 'username123';
$password = 'azerty321';
$email = 'example@example.com';
@EvanHerman
EvanHerman / functions.php
Created January 24, 2016 16:56
Localize the jquery datepicker in WordPress using the WP_Locale object
<?php
add_action( 'admin_enqueue_scripts', 'admin_print_js' );
public function admin_print_js() {
global $wp_locale;
//add the jQuery UI elements shipped with WP
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-datepicker' );