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 / git-create-repo.sh
Created May 22, 2019 06:16
A simple bash script to create a repository from the console.
#! /usr/bin/bash
NAME=$1
TYPE=$2
echo "Creating the repository"
gh re --browser false --new "$NAME" --type "$TYPE"
mkdir "$NAME"
cd "$NAME"
@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 / sticky-menu.js
Created March 5, 2019 05:46
Small JavaScript snippet to make the Genesis site header stick to the top when scrolling down.
jQuery(function ($) {
$(window).scroll(function () {
var yPos = ($(window).scrollTop());
if (yPos > 200) { // show sticky menu after screen has scrolled down 200px from the top.
// add a custom class to the site header for custom styling.
$(".site-header").addClass("is-sticky");
// if you feel brave, switch logos (e.g. to match different background colors).
$("img.custom-logo").attr("src", "http://localhost/wp-content/path/to/sticky-logo.svg");
} else {
@jan-koch
jan-koch / block.js
Created December 11, 2018 16:22
Functionality for the Gutenberg block to embed Github gists
/**
* BLOCK: wpmastery-code-block
*
* Registering a basic block with Gutenberg.
* Simple block, renders and saves the same content without any interactivity.
*/
// Import CSS.
import './style.scss';
import './editor.scss';
@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-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 / 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-hidden-input.php
Created November 15, 2018 14:49
Example implementation for a hidden field as WooCommerce product meta field, in the "General" tab.
<?php
function prefix_add_hidden_input() {
$args = array(
'value' => '', // meta_value, meta_key is the id
'class' => '',
'id' => '' // required, makes the meta_key for storing the value
);
woocommerce_wp_hidden_input( $args );
}
@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-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' ),