Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
helgatheviking / dequeue-script-example.php
Created Jan 6, 2021
Code snippet for dequeing a script on the single produt page
View dequeue-script-example.php
function kia_unload_script() {
if ( function_exists( 'is_product' ) && is_product() ) {
wp_dequeue_script( 'wc-single-product' );
}
}
add_action( 'wp_enqueue_scripts', 'kia_unload_script', 20 );
@helgatheviking
helgatheviking / wc-mnm-simplify-variation-names.php
Created Dec 11, 2020
Reduce Mix and Match variation names to only their attributes
View wc-mnm-simplify-variation-names.php
<?php
/**
* Plugin Name: WooCommerce Mix and Match Products - Simplify variation names
* Plugin URI: https://woocommerce.com/products/woocommerce-mix-and-match-products
* Description: Reduce container variation names to only their attributes
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: https://kathyisawesome.com
* Requires at least: 5.5
* Requires PHP: 7.0
@helgatheviking
helgatheviking / short-description-in-loop.php
Last active Oct 23, 2020
Display short descriptions in WooCommerce shop loops
View short-description-in-loop.php
<?php
/**
* Display short descriptions in loop
*/
function kia_display_short_desciption_in_loop() {
global $product;
$short_description = $product->get_short_description();
@helgatheviking
helgatheviking / kia-local-dev.php
Created Sep 9, 2020
Snippet for local WordPress development
View kia-local-dev.php
<?php
/**
* Plugin Name: Local Dev modifications
* Plugin URI: https://kathyisawesome.com/
* Description: Custom snippets for local development
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: https://kathyisawesome.com
*/
@helgatheviking
helgatheviking / wc-mnm-ups-bridge.php
Last active Sep 4, 2020
Add support for Mix and Match products to PluginHive UPS
View wc-mnm-ups-bridge.php
<?php
/**
* Plugin Name: WooCommerce Mix and Match - PluginHive UPS Bridge
* Plugin URI: http://www.woocommerce.com/products/woocommerce-mix-and-match-products/
* Description: Add support for Mix and Match products to UPS shipping.
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com/
* WC requires at least: 4.0.0
* WC tested up to: 4.4.0
@helgatheviking
helgatheviking / wc-mnm-external-grouping.php
Created Aug 12, 2020
Fix add to cart URL/text for external products that don't have an external URL
View wc-mnm-external-grouping.php
<?php
/**
* Plugin Name: Mix and Match external product parents
* Plugin URI: https://gist.github.com/helgatheviking/af72435b3cf729886b852c61c0f2d38c
* Description: Fix add to cart URL/text for external products that don't have an external URL. Like when using a product table to group products together.
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: https://kathyisawesome.com
* Text Domain: mnm-external-parent
* Domain Path: /i18n/languages/
@helgatheviking
helgatheviking / wc-sub-prevent-switching-before-renewal.php
Created Aug 4, 2020
Disable Mix and Match contents switching for timer window prior to renewal
View wc-sub-prevent-switching-before-renewal.php
/**
* Disable contents switching for window prior to renewal
*
* @param boolean $can
* @param WC_Order_Item $item
* @param WC_Subscription $subscription
* @return boolean
*/
public static function kia_prevent_modification_of_subscription( $can, $item, $subscription ) {
@helgatheviking
helgatheviking / mnm-rest-api-create-mix-and-match-product.txt
Created Jul 25, 2020
Create a WooCommerce Mix and Match product with it's settings
View mnm-rest-api-create-mix-and-match-product.txt
curl -X POST https://example.com/wp-json/wc/v3/products \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "Sample Six Pack",
"type": "mix-and-match",
"regular_price": "0",
"description": "So many products to choose from.",
"short_description": "Pick 6.",
"categories": [
@helgatheviking
helgatheviking / display-attributes-as-table.php
Created May 21, 2020
Display the WooCommerce product attributes as a table element via shortcode [display_attributes]
View display-attributes-as-table.php
<?php
/**
* Attributes shortcode callback.
*/
function so_39394127_attributes_shortcode( $atts ) {
global $product;
if( ! is_object( $product ) || ! $product->has_attributes() ){
@helgatheviking
helgatheviking / xdebug-var-dump.css
Created May 12, 2020
Style rules to make var_dump a hell of a lot more readable
View xdebug-var-dump.css
.xdebug-var-dump {
/* These are technically the same, but use both */
overflow-wrap: break-word;
word-wrap: break-word;
-ms-word-break: break-all;
/* This is the dangerous one in WebKit, as it breaks things wherever */
word-break: break-all;
/* Instead use this non-standard one: */