Skip to content

Instantly share code, notes, and snippets.

@helgatheviking
helgatheviking / simple.php
Last active Sep 20, 2021
Simple add to cart template - adds ajax add to cart support to simple products
View simple.php
<?php
/**
* Simple product add to cart with core ajax add to cart support
*
* This template should be saved to yourtheme/woocommerce/single-product/add-to-cart/simple.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
@helgatheviking
helgatheviking / shortcodes.php
Last active Aug 27, 2021
WooCommerce display a single product add to cart form with [add_to_cart_form]
View shortcodes.php
/**
* NB: updated version available here: https://github.com/helgatheviking/add-to-cart-form-shortcode
*/
/**
* Add [add_to_cart_form] shortcode that display a single product add to cart form
* Supports id and sku attributes [add_to_cart_form id=99] or [add_to_cart_form sku=123ABC]
* Essentially a duplicate of the [product_page]
* but replacing wc_get_template_part( 'content', 'single-product' ); with woocommerce_template_single_add_to_cart()
*
@helgatheviking
helgatheviking / kia_convert_country_code.php
Created Dec 7, 2015
Converts the WooCommerce country codes to 3-letter ISO codes
View kia_convert_country_code.php
<?php
/**
* Converts the WooCommerce country codes to 3-letter ISO codes
* https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
* @param string WooCommerce's 2 letter country code
* @return string ISO 3-letter country code
*/
function kia_convert_country_code( $country ) {
$countries = array(
'AF' => 'AFG', //Afghanistan
@helgatheviking
helgatheviking / add-taxonomy-to-woocommerce-export.php
Last active Aug 15, 2021
Add a custom taxonomy to WooCommerce import/export
View add-taxonomy-to-woocommerce-export.php
<?php
/*
* Plugin Name: WooCommerce Add Taxonomy to Export
* Plugin URI: https://gist.github.com/helgatheviking/114c8df50cabb7119b3c895b1d854533/
* Description: Add a custom taxonomy to WooCommerce import/export.
* Version: 1.0.1
* Author: Kathy Darling
* Author URI: https://kathyisawesome.com/
*
* Woo: 18716:fbca839929aaddc78797a5b511c14da9
@helgatheviking
helgatheviking / custom-modal-metabox.js
Last active Aug 8, 2021
Create a completely custom media frame (WIP)
View custom-modal-metabox.js
/**
* @type {Object} JavaScript namespace for our application.
*/
var Custom_Modal = {};
(function($, Custom_Modal) {
var $ = jQuery;
_.extend( Custom_Modal, { view: {}, controller: {} } );
@helgatheviking
helgatheviking / wordpress-add-custom-menu-meta-fields.php
Created Feb 26, 2020
Add an example custom meta field to WordPress menu and display text on front-end (Requires WP5.4)
View wordpress-add-custom-menu-meta-fields.php
<?php
/**
* Add custom fields to menu item
*
* This will allow us to play nicely with any other plugin that is adding the same hook
*
* @param int $item_id
* @params obj $item - the menu item
* @params array $args
@helgatheviking
helgatheviking / kia-sample-custom-field-for-woocommerce.php
Last active May 27, 2021
Add a custom text field to a WooCommerce Product
View kia-sample-custom-field-for-woocommerce.php
<?php
/**
* Plugin Name: Sample Customizable Product Field for WooCommerce
* Plugin URI: https://www.kathyisawesome.com/add-a-custom-field-to-woocommerce-product/
* Description: Add a custom text field to a WooCommerce Product
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com
* Requires at least: 5.2.0
* WC requires at least: 3.6.0
@helgatheviking
helgatheviking / woocommerce-shipping-contact.php
Last active May 6, 2021
Add a shipping email/phone field to checkout and notify of new orders
View woocommerce-shipping-contact.php
<?php
/*
Plugin Name: WooCommerce Shipping Contact
Plugin URI: https://github.com/helgatheviking/wc-shipping-contact
Description: Add a shipping email field to checkout and notify of new orders
Version: 1.1.0
Author: Kathy Darling
Author URI: http://kathyisawesome.com
Requires at least: 4.0
Tested up to: 4.8
@helgatheviking
helgatheviking / KIA-comment-blacklist.txt
Last active Apr 24, 2021
Customizing the WordPress Install Process with install.php - All files go in your /wp-content/ folder. http://www.kathyisawesome.com/421/customizing-wordpress-install/
View KIA-comment-blacklist.txt
_abercrombie
_account
_adidas
_advantage
_alviero
_article
_asics
_babe
_backup
_barata
@helgatheviking
helgatheviking / kia_add_script_to_footer.php
Created Feb 24, 2017
Add plus and minus buttons to WooCommerce quantity inputs
View kia_add_script_to_footer.php