Skip to content

Instantly share code, notes, and snippets.

View itms-theme-helpers.php
<?php
/**
* Plugin Name: Theme Showdown 2020 Helper Plugin
* Plugin URI: https://www.ithemes.com/training
* Description: Plugin that includes handy helpful code snippets for Theme Showdown 2020
* Author: iThemes / AJ Morris
* Author URI: https://www.ithemes.com/training
* Text Domain: ithemes-training
* Domain Path: /languages
* Version: 1.0.0
View sample function
<?php
// Adding this to get the form and entry object from Gravity Forms so I can test the connector.
add_action('gform_after_submission', 'print_form_and_entry_object', 10, 2);
function print_form_and_entry_object($entry, $form) {
ob_start();
var_dump($entry);
var_dump($form);
$contents = ob_get_contents();
ob_end_clean();
@ajmorris
ajmorris / functions.php
Created Dec 7, 2017
Code for WooCommerce to check if products in the cart belong to one of the categories we're looking for.
View functions.php
<?php
/**
* Check if a specific product category is in the cart
*/
function wc_ninja_category_is_in_the_cart() {
// Add your special category slugs here
$categories = array( 'clothing', 'posters' );
// Products currently in the cart
$cart_ids = array();
@ajmorris
ajmorris / functions.php
Created Dec 7, 2017
Remove checkout field if product IDs exist. WooCommerce / WordPress
View functions.php
<?php
/**
* Conditionally remove a checkout field based on products in the cart
*/
function wc_ninja_remove_checkout_field( $fields ) {
if ( ! wc_ninja_product_is_in_the_cart() ) {
unset( $fields['billing']['billing_company'] );
}
return $fields;
@ajmorris
ajmorris / functions.php
Created Dec 7, 2017
Check for specific Product IDs in your cart to return true if they are there. WooCommerce/WordPress
View functions.php
<?php
/**
* Check if a specific product ID is in the cart
*/
function wc_ninja_product_is_in_the_cart() {
// Add your special product IDs here
$ids = array( '45', '70', '75' );;
// Products currently in the cart
$cart_ids = array();
@ajmorris
ajmorris / custom-woo-acf-tabs.php
Created Apr 18, 2018
Create custom product details tabs within WooCommerce using an ACF (Advanced Custom Fields) Repeater field.
View custom-woo-acf-tabs.php
<?php
function hwid_load_custom_tab( $tab_key, $tab_info ) {
echo apply_filters( 'the_content', $tab_info['tabContent'] );
}
function hwid_add_content_tabs( $tabs ) {
global $post;
$custom_tabs = get_field( 'tabs', $post->ID );
@ajmorris
ajmorris / acf-fields.php
Last active Feb 7, 2020 — forked from hereswhatidid/acf-fields.php
Create custom product details tabs within WooCommerce using an ACF (Advanced Custom Fields) Repeater field.
View acf-fields.php
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'acf_product_options',
'title' => 'Product Options',
'fields' => array (
array (
'key' => 'acf_product_options_tabbedcontent_label',
'label' => 'Tabbed Content',
View gist:2014646
function mytheme_admin_bar_render() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('headway');
}
add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
@ajmorris
ajmorris / functions.php
Created Mar 28, 2018
WooCommerce - Adds stock status to the dropdown on product pages
View functions.php
<?php
add_action( 'woocommerce_after_add_to_cart_form', 'dropdown_waitlist_label' );
function dropdown_waitlist_label() {
echo "
<script>
jQuery(document).ready(function($) {
var variation_data = $('form.variations_form').attr('data-product_variations');
var variation_data = JSON.parse(variation_data);
$('#pa_size > option').each(function() {
for (var i = 0; i < variation_data.length; i++) {
@ajmorris
ajmorris / functions.php
Last active Aug 6, 2018
making the description display for menu items with description filled out
View functions.php
<?php
// Adds the descriptions to menu output
function prefix_nav_description( $item_output, $item, $depth, $args ) {
if ( !empty( $item->description ) ) {
$item_output = str_replace( $args->link_after . '</a>', '<p class="menu-item-description">' . $item->description . '</p>' . $args->link_after . '</a>', $item_output );
}
return $item_output;
}