Skip to content

Instantly share code, notes, and snippets.

@ajmorris
ajmorris / functions.php
Created December 7, 2017 04:08
Remove checkout field if product IDs exist. WooCommerce / WordPress
<?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 December 7, 2017 04:06
Check for specific Product IDs in your cart to return true if they are there. WooCommerce/WordPress
<?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 / functions.php
Created December 7, 2017 03:41
Remove checkout fields from WooCommerce Checkou
<?php
function wc_ninja_remove_checkout_field( $fields ) {
unset( $fields['billing']['billing_company'] );
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'wc_ninja_remove_checkout_field' );
// list of fields can be found here, https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
@ajmorris
ajmorris / functions.php
Created December 6, 2017 20:37
Add these few lines of code to your theme's functions.php file to allow you to change the number of products per page
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 9;
return $cols;
}
@ajmorris
ajmorris / reverse-proxy.php
Last active August 8, 2017 19:17 — forked from JamesPaden/reverse-proxy.php
Wordpress Reverse Proxy Plugin
<?php
/**
* @package Reverse Proxy
*/
/*
Plugin Name: Reverse Proxy
Plugin URI: https://instrumentalapp.com/
Description: Reverse proxy setup for Instrumental blog
Version: 1.0
Author: James Paden
@ajmorris
ajmorris / content.php
Created July 13, 2017 02:43
ExchangeWP Content page template
<?php
/**
* The default template for displaying content
*
* Used for both single and index/archive/search.
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
@ajmorris
ajmorris / archive.php
Created July 13, 2017 02:41
Product Archive page template ExchangeWP
<?php
/**
* The template for displaying Archive pages
*
* Used to display archive-type pages if nothing more specific matches a query.
* For example, puts together date-based pages if no date.php file exists.
*
* If you'd like to further customize these archive views, you may create a
* new template file for each specific one. For example, Twenty Fourteen
* already has tag.php for Tag archives, category.php for Category archives,
@ajmorris
ajmorris / functions.php
Created July 13, 2017 02:39
Login Redirect
/**
* Redirects users away from login page if they're already logged in
* or Redirects to /store/ if they log out.
*
* @since 0.4.0
*
* @return void
*/
function login_out_page_redirect() {
if ( is_user_logged_in() && 'login' == $this->_current_view ) {
<script type="text/javascript">
jQuery(document).ready(function($) {
var ref = $.cookie( 'affwp_ref' );
var visit = $.cookie( 'affwp_ref_visit_id' );
// If a referral var is present and a referral cookie is not already set
if( ref && visit ) {
// Fire an ajax request to log the hit
@ajmorris
ajmorris / kill_updates.php
Created August 4, 2016 19:14
Snippets of Killing Auto Updates for WordPress
<?php
// This constant allows different options: true, false, 'minor'. We need to have minor selected.
// Will auto update only minor releases, e.g. 4.3.2, 4.3.3, 4.3.4, etc.
define( 'WP_AUTO_UPDATE_CORE', 'minor' );
// This would disable ALL updates: WP core, plugins, and themes.
// We shouldn't need this unless we wanted to disable auto updates to everything.
define( 'AUTOMATIC_UPDATER_DISABLED', true );