Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
helgatheviking / free-item-shipping.php
Created October 4, 2015 00:20
Remove certain items from shipping calculations
function remove_free_shipping_items( $packages ) {
foreach( $packages as $i => $package ){
foreach ( $package['contents'] as $key => $item ) {
if ( $item['data']->get_shipping_class() == 'free' ) {
unset( $packages[$i]['contents'][$key] );
add_filter( 'woocommerce_cart_needs_shipping', '__return_true' );
@helgatheviking
helgatheviking / extra-step-to-js-multistep-checkout.php
Created March 11, 2017 18:20
Add Step to JC WooCommerce Multistep Checkout
/*
* Add new checkout fields
* See: https://www.kathyisawesome.com/woocommerce-customize-checkout-fields/ for saving/displaying order meta
*/
function kia_filter_checkout_fields( $fields ){
$fields['extra_fields'] = array(
'some_field' => array(
'type' => 'text',
'label' => __( 'Some field', 'your-plugin-textdomain' )
),
@helgatheviking
helgatheviking / limit-product-to-one-per-mnm-container.php
Created December 9, 2016 17:21
Limit a particular product to 1 per Mix and Match container
/**
* Limits the mix and match item's input quantity to 1
* @param int $qty - the max quantity allowed in this product's quantity input
* @param obj $mnm_item - the child product
* @param obj $product - the container product
* @return int
*/
function kia_set_max_mnm_quantity( $qty, $mnm_item, $product ){
$purple_id = 37; // product ID of the purple product;
$container_id = 220; // product ID of the mix and match container product
<?php
/**
* Plugin Name: Patch for WooCommerce Mix and Match plus Ultimate VC Addons
* Plugin URI: https://gist.github.com/helgatheviking/7360234c4bf6caf14732f1f21539625b
* Description: Ultimate VC Addons uses Select2 v3, so switch the MNM "legacy" version of allowed contents input.
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com/
* WC requires at least: 2.4.0
* WC tested up to: 3.2.0
@helgatheviking
helgatheviking / functions.php
Last active October 17, 2017 02:18
Add support for Name Your Price to grouped products
/**
* Add Name Your Price support to Grouped Products.
* Caveat: must override the /single-product/add-to-cart/grouped.php template and move
* <?php do_action( 'woocommerce_grouped_product_list_before_price', $grouped_product ); ?>
* inside the following element
* <td class="price">
* This is what I'm hoping will be merged into core: https://github.com/woocommerce/woocommerce/pull/17111
* Alternatively, you can add ANY hook name you want there as long as it matches the add_action() below
* For more information, read the docs: https://docs.woocommerce.com/document/template-structure/
@helgatheviking
helgatheviking / price-upon-request.php
Created May 6, 2017 17:49
Switch Free prices to "Price upon Request"
<?php
/**
* Plugin Name: Price Upon Request
* Plugin URI: https://gist.github.com/helgatheviking/6278f960f5fb7fca101e75f30f33141c
* Description: Switch Free prices to "Price upon Request"
* Version: 0.1.0
* Author: helgatheviking
* Author URI: https://kathyisawesome.com
* Requires at least: 4.7
* Tested up to: 4.7
@helgatheviking
helgatheviking / hide-products-if-logged-out.php
Created December 5, 2017 23:03
Hide specific products from query if logged out (does not prevent direct access)
add_action( 'woocommerce_product_options_stock_status', 'so_27971630_hide_if_logged_out' );
function so_27971630_hide_if_logged_out(){
woocommerce_wp_checkbox( array( 'id' => '_hide_if_logged_out', 'wrapper_class' => 'show_if_simple show_if_variable', 'label' => __( 'Hide this product from archives when not logged in?', 'your-plugin-domain' ) ) );
}
add_action( 'woocommerce_admin_process_product_object', 'so_27971630_save_product_meta' );
@helgatheviking
helgatheviking / wc-mnm-display-child-prices.php
Last active June 25, 2018 17:16
Display individual MNM option prices
<?php
/**
* Display individual MNM option prices
*
* @param obj $mnm_item WC_Product of child item
* @param obj WC_Mix_and_Match $product the parent container
*/
function kia_add_individual_prices( $mnm_item, $parent_product ) {
if( $parent_product->is_priced_per_product() ) {
echo '<p class="price">' . $mnm_item->get_price_html() . '</p>';
@helgatheviking
helgatheviking / wc-mnm-remove-thumbnail.php
Last active June 25, 2018 17:18
Remove thumbnail column from MNM product options
<?php
/**
* Remove thumbnail column from MNM product options
* The table column header must be removed by overriding the single-product/mnm/tablular/mnm-items-wrapper-open.php template
*/
function kia_remove_thumbnail_column() {
remove_action( 'woocommerce_mnm_child_item_details', 'wc_mnm_template_child_item_thumbnail_open', 10 );
remove_action( 'woocommerce_mnm_child_item_details', 'wc_mnm_template_child_item_thumbnail', 20 );
remove_action( 'woocommerce_mnm_child_item_details', 'wc_mnm_template_child_item_section_close', 30 );
add_filter( 'woocommerce_mnm_tabular_column_headers', 'kia_remove_thumbnail_column_header' );
@helgatheviking
helgatheviking / wc-mnm-display-description.php
Last active June 25, 2018 17:19
Display description on each child product in a Mix and Match container
<?php
/**
* Display individual MNM option descriptions
*
* @param obj $mnm_item WC_Product of child item
* @param obj WC_Mix_and_Match $product the parent container
*/
function kia_add_individual_info( $mnm_item, $parent_product ) {
echo '<p class="desc">' . $mnm_item->get_short_description() . '</p>';
}