Skip to content

Instantly share code, notes, and snippets.

@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
@helgatheviking
helgatheviking / kia-sample-custom-field-for-woocommerce.php
Last active May 26, 2022
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.1.0
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com
* Requires at least: 5.2.0
* Tested up to: 5.2.2
@helgatheviking
helgatheviking / class-wc-kia-class-email.php
Last active May 11, 2022
Send a WooCommerce Customer email from the Order Admin Actions
View class-wc-kia-class-email.php
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'WC_KIA_Class_Email', false ) ) :
/**
* A custom Order WooCommerce Email class
*
* @since 0.1
* @extends \WC_Email
@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 / shortcodes.php
Last active Apr 14, 2022
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 / billing-details-translation.php
Created Apr 12, 2022
Change Billing Details text on free checkout
View billing-details-translation.php
function kia_translate_billing_details_when_free( $translated_text, $untranslated_text, $domain ) {
if ( function_exists( 'wc' ) && 'woocommerce' === $domain ) {
//make the changes to the text
switch( $untranslated_text ) {
case 'Billing details':
if ( ! WC()->cart->needs_shipping() && 0.0 === floatval( WC()->cart->get_total( 'edit' ) ) ) {
$translated_text = __( 'NOT billing details', 'kia_textdomain' );
@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 / add-taxonomy-to-woocommerce-export.php
Last active Mar 21, 2022
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 / wc-clear-persistent-carts-daily.php
Created Mar 8, 2022
Schedule a task to run daily to delete WooCommerce persistent carts
View wc-clear-persistent-carts-daily.php
<?php
/**
* Plugin Name: Clear persistent carts daily
* Plugin URI: https://gist.github.com/
* Description: Schedule a task to run daily to delete WooCommerce persistent carts
* Version: 1.0.0
* Author: Kathy Darling
* Author URI: http://kathyisawesome.com/
* WC requires at least: 6.3.0
* WC tested up to: 6.3.0
@helgatheviking
helgatheviking / simple.php
Last active Jan 27, 2022
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