Skip to content

Instantly share code, notes, and snippets.

View mtruitt's full-sized avatar

Mark Truitt mtruitt

  • Maryland
View GitHub Profile
@mtruitt
mtruitt / coupon_multi.php
Created November 15, 2017 20:18
Auto applies Coupon w/ use of a different coupon.
<?php
/*
* Auto applies coupon code based on another coupon code and removes all if either is removed
*/
function auto_apply_coupon() {
$applied_coupon_code = 'Coupon manually applied goes here';
$coupon_code = 'coupon you want auto applied';
if ( WC()->cart->has_discount($applied_coupon_code) ) {
@mtruitt
mtruitt / woocommerce_shipping.php
Created July 17, 2017 20:40
Set a minimum shipping value
<?php
function wc_minimum_shipping_amount() {
// Set this variable to specify a minimum shipping value
$minimum = 1;
$shipping_total = round( WC()->cart->total, 2 ) - round( WC()->cart->subtotal, 2 );
if ( $shipping_total <= $minimum ) {
wc_add_notice(
sprintf( 'No shipping method applied. Please refresh the page and try again.'
), 'error'
@mtruitt
mtruitt / wc_support.php
Created June 29, 2017 18:27
WooCommerce Theme Support 3.X
<?php
add_action( 'after_setup_theme', 'wc_support' );
function wc_support() {
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
@mtruitt
mtruitt / coupons.php
Created June 13, 2017 20:38
Auto apply coupon code
<?php
add_action( 'woocommerce_before_cart', 'apply_matched_coupons' );
function apply_matched_coupons() {
global $woocommerce;
$coupon_code = 'JunePromo'; // your coupon code here
if ( $woocommerce->cart->has_discount( $coupon_code ) ) return;
@mtruitt
mtruitt / remove_ratings.php
Created May 26, 2017 15:41
WooCommerce - Remove rating stars from product loop
<?php
// Remove product rating stars from product loop
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
@mtruitt
mtruitt / continue_shopping_cart_link.php
Last active May 26, 2017 15:44
WooCommerce - Continue Shopping Cart link
@mtruitt
mtruitt / increase_product_variations_per_page.php
Created April 16, 2017 15:52
Increase how many product variations display per page
<?php
function filter_increase_product_variations_per_page() {
return 50;
}
add_filter( 'woocommerce_admin_meta_boxes_variations_per_page', 'filter_increase_product_variations_per_page', 10, 1 );
@mtruitt
mtruitt / woocommerce_minimum_order_limit.php
Created March 14, 2017 19:24
WooCommerce Minimum Order Limit
<?php
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 25;
if ( WC()->cart->subtotal < $minimum ) {
if( is_cart() ) {
wc_print_notice(
@mtruitt
mtruitt / woocommerce_validation.php
Last active March 14, 2017 19:25
Validation for WooCommerce being present and active
<?php
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
}
@mtruitt
mtruitt / woo_hide_coupon.php
Last active April 20, 2017 18:52
Hide Coupon Field
<?php
// Hide coupon field
function hide_coupon_field( $enabled ) {
if ( is_cart() ) {
$enabled = false;
}
return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field' );