Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
helgatheviking / short-description-in-loop.php
Last active October 23, 2020 00:01
Display short descriptions in WooCommerce shop loops
<?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 September 9, 2020 22:34
Snippet for local WordPress development
<?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 September 4, 2020 15:51
Add support for Mix and Match products to PluginHive UPS
<?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 August 12, 2020 16:48
Fix add to cart URL/text for external products that don't have an external URL
<?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 August 4, 2020 21:00
Disable Mix and Match contents switching for timer window prior to renewal
/**
* 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 July 25, 2020 17:17
Create a WooCommerce Mix and Match product with it's settings
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 14:52
Display the WooCommerce product attributes as a table element via shortcode [display_attributes]
<?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 19:47
Style rules to make var_dump a hell of a lot more readable
.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: */
<?php
/**
* @package KIA Subtitle
* @category Compatibility Class
* @version 3.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
@helgatheviking
helgatheviking / add-win-terminal-ubuntu-profile-to-context-menus.reg
Last active July 2, 2020 05:32
Add "Open Ubuntu Terminal Here" to context menus - Launches Windows Terminal's Ubuntu profile.
Windows Registry Editor Version 5.00
Replace <<Username>> with your user name!
[HKEY_CLASSES_ROOT\Directory\Background\shell\ubuntu]
@="Open Ubuntu Terminal here"
"Icon"="%USERPROFILE%/AppData/Local/WindowsTerminal/ubuntu.ico"
[HKEY_CLASSES_ROOT\Directory\Background\shell\ubuntu\command]
@="C:\\Users\\<<Username>>\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -d . --profile=\"Ubuntu-18.04\""