Skip to content

Instantly share code, notes, and snippets.

View jan-koch's full-sized avatar

Jan Koch jan-koch

View GitHub Profile
@jan-koch
jan-koch / functions.php
Created April 9, 2019 14:11
Remove comments from the single post layout in the WP Astra theme. This snippet goes into your functions.php.
// Remove the default comments from Astra.
add_action(
'init',
function() {
if ( class_exists( 'Astra_Loop' ) ) {
remove_action( 'astra_template_parts_content', array( Astra_Loop::get_instance(), 'template_parts_comments' ), 15 );
}
},
11
);
@jan-koch
jan-koch / woo-add-custom-sku.php
Last active July 16, 2021 10:39
Add a custom SKU field to WooCommerce products.
<?php
function jk_add_custom_sku() {
$args = array(
'label' => __( 'Custom SKU', 'woocommerce' ),
'placeholder' => __( 'Enter custom SKU here', 'woocommerce' ),
'id' => 'jk_sku',
'desc_tip' => true,
'description' => __( 'This SKU is for internal use only.', 'woocommerce' ),
);
@jan-koch
jan-koch / email-order-items.php
Last active April 17, 2021 15:41
Email order items template from WooCommerce, containing a custom snippet to show a custom SKU for each product - only in admin emails. This file goes into wp-content/themes/your-child-theme/woocommerce/emails.
<?php
/**
* Email Order Items
*
* This template can be overridden by copying it to yourtheme/woocommerce/emails/email-order-items.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
@jan-koch
jan-koch / woo-selectbox.php
Created November 15, 2018 13:09
Example of adding a select box to the "General" product data tab.
<?php
function prefix_add_selectbox() {
$args = array(
'id' => 'my_new_select', // required. The meta_key ID for the stored value
'wrapper_class' => '', // a custom wrapper class if needed
'desc_tip' => true, // makes your description show up with a "?" symbol and as a tooltip
'description' => __('My awesome select box', 'your_text_domain'),
'label' => __( 'My New Select', 'your_text_domain' ),
'options' => array(
'value1' => __( 'Text 1', 'your_text_domain' ),
@jan-koch
jan-koch / woo-radio-button.php
Last active January 23, 2021 15:09
Example implementation of radio buttons as product meta fields, in the "General" tab.
<?php
function prefix_add_radio_buttons() {
$args = array(
'label' => '', // Text in the label in the editor
'class' => 'prefix_radio', // custom class
'style' => '',
'wrapper_class' => '', // custom wrapper class
'value' => '', // if empty, retrieved from meta_value where id is the meta_key
'id' => '', // required, will be used as meta_key for this field
'name' => 'my_radio_buttons', // required if you want only one option to be selected at a time
@jan-koch
jan-koch / woo-checkbox-input.php
Created November 15, 2018 14:54
Example for implementing a checkbox as WooCommerce product meta field, in the "General" tab.
<?php
function prefix_add_checkbox() {
$args = array(
'label' => '', // Text in the editor label
'class' => '',
'style' => '',
'wrapper_class' => '', // custom CSS class for styling
'value' => '', // meta_value where the id serves as meta_key
'id' => '', // required, it's the meta_key for storing the value (is checked or not)
'name' => '',
@jan-koch
jan-koch / woo-textarea.php
Created November 15, 2018 12:05
Example of adding a custom textarea to the "General" tab of a WooCommerce product.
<?php
function prefix_add_textarea() {
$args = array(
'label' => '', // Text in the label in the editor view
'placeholder' => '', // Give advice or examples as placeholder
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, will be loaded as meta_value for the meta_key with the given id
@jan-koch
jan-koch / woo-text-input.php
Created November 15, 2018 10:35
Example for adding a text input field to the WooCommerce "General" tab.
<?php
function prefix_add_text_input() {
$args = array(
'label' => '', // Text in the label in the editor.
'placeholder' => '', // Give examples or suggestions as placeholder
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post_meta
'id' => '', // required, will be used as meta_key
@jan-koch
jan-koch / piccia.css
Created August 15, 2020 16:53
CSS for Piccia's progress bar
.gf_progressbar {
margin-left: -40px;
}
.gf_progressbar .gf_progressbar_percentage > span {
position: absolute;
left: -40px;
top: -2px;
}
@jan-koch
jan-koch / remove-woo-scripts.php
Created February 28, 2020 09:14
Remove WooCommerce related resources except on WooCommerce-based pages (products, cart, checkout, etc). Use on a testing environment before pasting this into your live website!
/**
* This code snippet removes JavaScript and CSS files loaded from WooCommerce if they are not necessary.
*
* Please test this on a staging copy of your website before putting this into the functions.php of your live website.
*/
add_action( 'wp_enqueue_scripts', 'my_remove_woo_assets', 99 );
function my_remove_woo_assets() {
if ( function_exists( 'is_woocommerce' ) ) { // Check if Woo is installed.
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) { // Only run on non-Woo pages.
// Remove unnecessary stylesheets.