Skip to content

Instantly share code, notes, and snippets.

View bolderelements's full-sized avatar

Erica Dion bolderelements

View GitHub Profile
@bolderelements
bolderelements / form-restocking.php
Last active January 27, 2018 02:12
Restocking Form Override (No Hooks)
<?php
// Add restocking form container
if( class_exists( 'BE_Product_Alerts_Form_Restocking' ) ) {
// check if enabled
$bepa_settings = get_option( 'woocommerce_product-alerts-restocking_settings' );
if( ! is_admin() && $bepa_settings['enabled'] !== 'no' ) {
// check if the single product is out of stock
if( ! $product->is_type( 'variable' ) && ! $product->is_in_stock() ) {
@bolderelements
bolderelements / betrs-add-dimensions-sum-condition.php
Last active December 4, 2017 04:08
Add new condition to Table Rate settings page
/**
* Add ability to compare the sum of all dimensions to Table Rate shipping
* https://codecanyon.net/item/table-rate-shipping-for-woocommerce/3796656?ref=bolderelements
*
* Code should be added to theme's functions.php file
*/
function betrs_add_dimensions_sum_cond( $conditions ) {
// add new option to list
$conditions['dimensions_sum'] = 'Dimensions Sum';
@bolderelements
bolderelements / hide-shipping-based-on-class.php
Last active July 31, 2019 15:34
Hide Shipping Method When Cart Contains Shipping Class
/**
* Hide a free shipping option (instance #7) when the given shipping class is in the cart
* Code snippets should be added to the functions.php file of your child theme
*
* @return array
*/
function hide_shipping_when_class_is_in_cart( $rates, $package ) {
// shipping class IDs that need the method removed
$shipping_classes = array('bulky-items');
$if_exists = false;
@bolderelements
bolderelements / hide-shipping-based-on-class-all.php
Last active September 25, 2017 18:49
Hide All Free Shipping Options When Cart Contains a Shipping Class
/**
* Hide all free shipping options when the given shipping class is in the cart
* Code snippets should be added to the functions.php file of your child theme
*
* @return array
*/
function hide_shipping_when_class_is_in_cart( $rates, $package ) {
// shipping class IDs that need the method removed
$shipping_classes = array('bulky-items');
$if_exists = false;
@bolderelements
bolderelements / woocommerce-remove-virtual-billing-fields.php
Last active October 12, 2017 23:14 — forked from BFTrick/woocommerce-remove-virtual-billing-fields.php
Remove the billing address fields for free virtual orders in WooCommerce
<?php
/**
* Plugin Name: WooCommerce Remove Billing Fields for Free Virtual Products
* Plugin URI: https://gist.github.com/bolderelements/caf09b527e1d42b3992c5a118729f0d7
* Description: Remove the billing address fields for free virtual orders, with the exception of email addresses
* Author: Erica Dion
* Author URI: http://bolderelements.net/
* Version: 1.0
*
* This program is free software: you can redistribute it and/or modify
@bolderelements
bolderelements / hide-payment-based-on-shipping.php
Last active February 19, 2018 20:43
Hide Payment Gateway Based on Shipping Option Selected
/**
* Hide the PayPal payment option when the customer selects a specific Table Rate option
* Code snippets should be added to the functions.php file of your child theme
*
* @return array
*/
function alter_payment_gateways( $list ){
// Retrieve chosen shipping options from all possible packages
$chosen_rates = ( isset( WC()->session ) ) ? WC()->session->get( 'chosen_shipping_methods' ) : array();
@bolderelements
bolderelements / base-fees-table-rate-shipping.php
Last active November 26, 2017 21:03
Add Different Base Fee to Shipping Option
add_filter( 'woocommerce_package_rates', 'add_shipping_option_base_fee', 10, 2 );
function add_shipping_option_base_fee( $rates, $package ) {
foreach( $rates as $key => $rate ) {
// reset defaults
$highest_priority = $highest_class = 0;
// Do not apply base fee if not the right option
if( $rate->id !== 'betrs_shipping:1-1' ) continue;
@bolderelements
bolderelements / hide-shipping-subtotal-based.php
Created January 17, 2018 20:47
Hide Shipping Method Based on Subtotal
add_filter( 'woocommerce_package_rates', 'hide_shipping_based_on_subtotal', 10, 2 );
function hide_shipping_based_on_subtotal( $rates, $package ) {
// Retrieve cart subtotal
$cart_subtotal = $package['contents_cost'];
// Shipping rate to be excluded
$shipping_id = 'betrs-shipping:3-1';
if( $cart_subtotal >= 500 )
unset( $rates[ $shipping_id ] );
@bolderelements
bolderelements / add-surcharge-for-shipping-large-items.php
Last active June 20, 2018 03:04
Add shipping for surcharge for large items
add_filter( 'woocommerce_package_rates', 'add_shipping_option_base_fee', 10, 2 );
function add_shipping_option_base_fee( $rates, $package ) {
foreach( $rates as $key => $rate ) {
// reset defaults
$highest_length = 0;
// Do not apply base fee if not the right option
if( $rate->id !== 'betrs_shipping:1-1' ) continue;
@bolderelements
bolderelements / add-surcharge-for-shipping-class-items.php
Last active February 14, 2018 02:52
Add shipping surcharge for one class of items in cart
add_filter( 'woocommerce_package_rates', 'add_shipping_option_base_fee', 10, 2 );
function add_shipping_option_base_fee( $rates, $package ) {
foreach( $rates as $key => $rate ) {
// reset defaults
$class_c_items = 0;
// Do not apply base fee if not the right option
if( $rate->id !== 'betrs_shipping:1-1' ) continue;