Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
helgatheviking / functions
Last active August 29, 2015 14:18
WooCommerce Name Your Price: Make NYP field required
add_filter( 'woocommerce_add_to_cart_validation', 'woocommerce_nyp_make_field_required', 10, 5 );
function woocommerce_nyp_make_field_required( $passed, $product_id, $quantity, $variation_id = '', $variations= '' ) {
if( $variation_id )
$product_id = $variation_id;
// skip if not a nyp product - send original status back
if ( ! WC_Name_Your_Price_Helpers::is_nyp( $product_id ) ){
return $passed;
@helgatheviking
helgatheviking / nf-aweber-custom-error-messages.php
Last active December 24, 2015 18:40
Ninja Forms AWeber: Custom error messages
/*
* Custom AWeber Error Messages
*
* @param $msg - current message from Ninja Forms for AWeber
* @param $error_code - null, placeholder for when AWeber gets error codes
* @param $error_message - original message from AWeber
* @param $subscriber - array of info about the subscriber submitted via form
* -- nb the form's ID can be found in $subscriber['form_id']
* @param $list_id the list ID
*/
@helgatheviking
helgatheviking / ninja-forms-aweber-suppress-specific-error.php
Last active September 10, 2016 23:59
Ninja Forms AWeber Suppress certain errors
/*
* Submit form even if user is already subscribed to AWeber List
*
* @param $msg - current message from Ninja Forms for AWeber
* @param $error_message - original message from AWeber
* @param $error_code - null, placeholder for when AWeber gets error codes
* @param $subscriber - array of info about the subscriber submitted via form
* -- nb the form's ID can be found in $subscriber['form_id']
* @param $list_id the list ID
*/
@helgatheviking
helgatheviking / functions.php
Created July 30, 2015 18:37
Ninja Forms AWeber: Suppress Errors
/*
* Submit form even if user is already subscribed to AWeber List
*
* @param $msg - current message from Ninja Forms for AWeber
* @param $error_code - null, placeholder for when AWeber gets error codes
* @param $error_message - original message from AWeber
* @param $subscriber - array of info about the subscriber submitted via form
* -- nb the form's ID can be found in $subscriber['form_id']
* @param $list_id the list ID
*/
@helgatheviking
helgatheviking / free-item-shipping.php
Created October 4, 2015 00:20
Remove certain items from shipping calculations
function remove_free_shipping_items( $packages ) {
foreach( $packages as $i => $package ){
foreach ( $package['contents'] as $key => $item ) {
if ( $item['data']->get_shipping_class() == 'free' ) {
unset( $packages[$i]['contents'][$key] );
add_filter( 'woocommerce_cart_needs_shipping', '__return_true' );
@helgatheviking
helgatheviking / nmr-session-roles.php
Created October 13, 2015 17:42
Hide custom menu items based on session variables
<?php
/*
Plugin Name: Nav Menu Roles + Session Roles
Plugin URI: http://www.kathyisawesome.com/449/nav-menu-roles/
Description: Hide custom menu items based on session variables
Version: 1.0.0
Author: Kathy Darling
Author URI: http://www.kathyisawesome.com
License: GPL-3.0
@helgatheviking
helgatheviking / functions.php
Created November 29, 2015 07:19
Add multiple wp_editor() inputs to a single metabox. Save as single meta value.
/**
* Adds a box to the main column on the Post and Page edit screens.
*/
function myplugin_add_meta_box() {
$screens = array( 'post', 'page' );
foreach ( $screens as $screen ) {
add_meta_box(
@helgatheviking
helgatheviking / kia_convert_country_code.php
Created December 7, 2015 19:01
Converts the WooCommerce country codes to 3-letter ISO codes
<?php
/**
* Converts the WooCommerce country codes to 3-letter ISO codes
* https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
* @param string WooCommerce's 2 letter country code
* @return string ISO 3-letter country code
*/
function kia_convert_country_code( $country ) {
$countries = array(
'AF' => 'AFG', //Afghanistan
@helgatheviking
helgatheviking / list-hooks.php
Created February 16, 2016 15:49
Advanced debugging of all functions attached to a specific filter
/**
* Even fancier debug info
* @props @Danijel http://stackoverflow.com/a/26680808/383847
* @since 1.7.7
*/
function list_hooks( $hook = '' ) {
global $wp_filter;
$hooks = isset( $wp_filter[$hook] ) ? $wp_filter[$hook] : array();
$hooks = call_user_func_array( 'array_merge', $hooks );
@helgatheviking
helgatheviking / ninja-forms-suppress-all-errors.php
Last active March 4, 2016 16:36
Ninja Forms AWeber Suppress all errors: Ninja Forms AWeber 1.3.1 is required for this to work
/*
* Suppress ALL AWeber errors and submit form
*/
add_filter( 'ninja_forms_aweber_show_errors', '__return_false' );
/*
* Suppress ALL AWeber errors on form id=5 and submit form
*
* @param $msg - current message from Ninja Forms for AWeber