Skip to content

Instantly share code, notes, and snippets.

View munts's full-sized avatar

Scott Taylor munts

  • confluence web solutions
  • Colorado
View GitHub Profile
@munts
munts / gist:7a7d3803d4add08fe41f9199d337e0c1
Created September 10, 2020 23:42
WooCommerce - Check cart amount and applied coupons to determine shipping options. If excluded coupon is in the applied coupon, remove free shipping and force flat rate shipping....
/* Change shipping based on total cost purchased and or applied coupons are excluded. */
add_filter( 'woocommerce_shipping_packages', 'hide_flat_rate_if_cart_total_is_greater_than_threshold', 5, 1 );
function hide_flat_rate_if_cart_total_is_greater_than_threshold( $packages ) {
$threshold1 = 249;
$applied_coupons = WC()->session->get( 'applied_coupons', array() );
$amount = WC()->cart->cart_contents_total;
$availableRates = $packages[0]['rates'];
$excluded_coupons = array('coupon1', 'coupon2', 'coupon3', 'coupon4', 'coupon5', 'coupon6', 'cooupon7', 'eight', 'nine', 'ten');
$isExcludedCoupon = false;
@munts
munts / settings.js
Created August 26, 2020 23:57
change classes on owl items based on active item so that active item can get special treatment, but remove class as it passes by...
$(function(){
$('.loop').on('initialized.owl.carousel translate.owl.carousel', function(e){
idx = e.item.index;
$('.owl-item.active.big').removeClass('big');
$('.owl-item.medium').removeClass('medium');
$('.owl-item').eq(idx).addClass('big');
$('.owl-item').eq(idx-1).addClass('medium');
$('.owl-item').eq(idx+1).addClass('medium');
$('.owl-item').eq(idx+2).addClass('medium');
@munts
munts / gist:2941c00cd7f8b89c30042e88a2840354
Created August 26, 2020 19:37
Remove 'Free Shipping' option if user applies coupon code to WooCommerce cart. Ie. if using coupon, do not provide free shipping.
add_filter( 'woocommerce_shipping_packages', function( $packages ) {
$applied_coupons = WC()->session->get( 'applied_coupons', array() );
if ( ! empty( $applied_coupons ) ) {
if ( in_array('promocode1', $applied_coupons) ||
in_array('promocode2', $applied_coupons)
) {
$free_shipping_id = 'woodiscountfree';
unset($packages[0]['rates'][$free_shipping_id]);
}
}
@munts
munts / gist:336cd6998a19e0818c13ee12d35bdec6
Created August 26, 2020 19:10
Set WooCommerce base location so that local city/county taxes are charged if local pickup is selected as the shipping option.
add_filter( 'woocommerce_countries_base_postcode', 'force_local_pickup_tax_location_zip' );
function force_local_pickup_tax_location_zip(){
return '90210';
}
add_filter( 'woocommerce_countries_base_city', 'force_local_pickup_tax_location_city' );
function force_local_pickup_tax_location_city(){
return 'Beverly Hills';
@munts
munts / gist:04deefaed8c503e7ed423ec89879f81c
Last active August 26, 2020 14:12
prevent parent item from being clickable if it has children items
$("ul.menu li:has(ul.nav-drop)").hover(function () {
$(this).children("a").click(function () {
return false;
});
});
<ul class="menu">
<li class="menu-item menu-item--current">
<a class="menu-link" href="http://sitzmark.local/about-us/">About Us</a>
@munts
munts / gist:b91591016757f027595f5ef6f49cc9dc
Created August 25, 2020 23:15
add custom styles to the WordPress TinyMCE editor
/*================= custom wysiwyg editor styles ==============*/
//add custom styles to the WordPress editor
function my_custom_styles( $init_array ) {
$style_formats = array(
// These are the custom styles
array(
'title' => 'Testimonials',
'block' => 'div',
'classes' => 'testimonials',
@munts
munts / gist:5ce18b4b3700632f1dbef34aa496d708
Created August 25, 2020 19:55
extend valid html elements to the WordPress tinymce editor - ie. script tags and even i tags for font awesome tags so that the editor doesn't strip them from content.
add_filter('tiny_mce_before_init', function( $a ) {
$a["extended_valid_elements"] = 'script';
return $a;
});
@munts
munts / gist:73dfb3e70ea0adbf4e94b38843607dd1
Created August 25, 2020 16:16
Make coupons invalid at product level & Set the product discount amount to zero
// Make coupons invalid at product level
add_filter('woocommerce_coupon_is_valid_for_product', 'set_coupon_validity_for_excluded_products', 12, 4);
function set_coupon_validity_for_excluded_products($valid, $product, $coupon, $values ){
if( ! count(get_option( '_products_disabled_for_coupons' )) > 0 ) return $valid;
$disabled_products = get_option( '_products_disabled_for_coupons' );
if( in_array( $product->get_id(), $disabled_products ) )
$valid = false;
return $valid;
@munts
munts / functions.php
Last active August 26, 2020 19:33
Hide WooCommerce shipping options when free shipping is available. Ie. hide Flat Rate.
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 100 );
function hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
break;
}
}
return ! empty( $free ) ? $free : $rates;
@munts
munts / functions.php
Last active August 26, 2020 19:26
Remove Flat Rate Shipping in WooCommerce if Customer Qualifies for Free Shipping with cart total greater than specific amount
/* Change shipping based on cart total and if they they qualify for free shipping */
add_filter( 'woocommerce_package_rates', 'hide_flat_rate_if_cart_total_is_greater_than_threshold', 5, 1 );
function hide_flat_rate_if_cart_total_is_greater_than_threshold( $rates ) {
$threshold1 = 249;
$amount = WC()->cart->cart_contents_total;
if ( $amount > $threshold1 ) {
unset( $rates['flat_rate:5'] );
}
return $rates;
}