Skip to content

Instantly share code, notes, and snippets.

AJ Morris ajmorris

Block or report user

Report or block ajmorris

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ajmorris
ajmorris / custom-woo-acf-tabs.php
Created Mar 28, 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 );
foreach( $custom_tabs as $index => $tab ) {
$tabs['customTab-' . $index] = array(
'title' => $tab['tab_title'],
@ajmorris
ajmorris / acf-fields.php
Created Mar 27, 2018
Create custom product details tabs for WooCommerce products with the ACF 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',
@ajmorris
ajmorris / wp-config.php
Created Mar 8, 2018
Hide PHP Warnings and Notices in WP
View wp-config.php
<?php
// Add these to your wp-config.php file.
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);
View gist:cf5bd3b6c2be5e96cefe36ed72f7d247
<a href="#idname"><img src="img/url" /></a>
<h1 id="#idname">title</h1>
@ajmorris
ajmorris / functions.php
Created Dec 12, 2017
quick code snippet to filter featured products in WooCommerce.
View functions.php
<?php
add_action('restrict_manage_posts', 'featured_products_sorting');
function featured_products_sorting() {
global $typenow;
$post_type = 'product'; // change to your post type
$taxonomy = 'product_visibility'; // change to your taxonomy
if ($typenow == $post_type) {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
@ajmorris
ajmorris / functions.php
Created Dec 7, 2017
remove the "are you sure" message from logging out of WooCommerce.
View functions.php
<?php
/**
* Bypass logout confirmation.
*/
function iconic_bypass_logout_confirmation() {
global $wp;
if ( isset( $wp->query_vars['customer-logout'] ) ) {
wp_redirect( str_replace( '&amp;', '&', wp_logout_url( wc_get_page_permalink( 'myaccount' ) ) ) );
exit;
@ajmorris
ajmorris / functions.php
Created Dec 7, 2017
When no WooCommerce products are found, show your visitor your features products
View functions.php
<?php
add_action( 'woocommerce_no_products_found', 'show_products_on_no_products_found', 20 );
function show_products_on_no_products_found() {
echo '<h2>' . __( 'You may be interested in...', 'domain' ) . '</h2>';
echo do_shortcode( '[featured_products per_page="4"]' );
}
@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();
You can’t perform that action at this time.