Skip to content

Instantly share code, notes, and snippets.

View benhuson's full-sized avatar

Ben Huson benhuson

View GitHub Profile
@lukecav
lukecav / Queries
Created June 30, 2023 20:52
Delete Action Scheduler actions with a status of failed and canceled and truncate the Action Scheduler logs database table
DELETE FROMwp_actionscheduler_actions WHERE status IN ('failed','canceled')
TRUNCATE wp_actionscheduler_logs
@jmccall75
jmccall75 / functions.php
Last active January 9, 2024 03:15
Locking down Gutenberg...
<?php
/**
* Gutenberg Block customization for this theme.
*/
// gutenberg disable for posts
//add_filter('use_block_editor_for_post', '__return_false', 10);
// gutenberg disable for post types
//add_filter('use_block_editor_for_post_type', '__return_false', 10);
@mtx-z
mtx-z / wp-woocommerce-allow-non-variation-attributes-frontend-selection.php
Last active March 31, 2024 17:02
Woocommerce: use non-variation attributes from frontend - allow customers to select term (option) from non-variation attributes on variable or simple products frontend pages, add selection to cart item, display it in cart, add it to order item
<?php
/**
* Inspired from: https://gist.github.com/dazecoop/548b2621e86fb030da8e5adb1bfe484f
*
* How to use:
* - add to your function.php or related
*
* What you can use it for:
* Variable products:
* - you have variable product with some attributes not used for variations
@dazecoop
dazecoop / attributes-as-options.php
Last active April 16, 2024 02:57
WooCommerce product attributes as selectable options without variations
<?php
/**
* List available attributes on product page in a drop-down selection
*/
add_action('woocommerce_before_add_to_cart_button', 'list_attributes_on_product_page');
function list_attributes_on_product_page() {
global $product;
$attributes = $product->get_attributes();
@pento
pento / php-block.js
Last active February 29, 2024 01:31
Converting a shortcode to a block: this method is fast to do, but a mediocre UX. You should only use this as a stopgap until you can implement a full block UI.
// License: GPLv2+
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
ServerSideRender = wp.components.ServerSideRender,
TextControl = wp.components.TextControl,
InspectorControls = wp.editor.InspectorControls;
/*
* Here's where we register the block in JavaScript.
@pento
pento / stars-block.js
Last active January 4, 2022 14:00
Gutenberg Stars Block
( function( blocks, element ) {
var el = element.createElement;
function Stars( { stars } ) {
return el( 'div', { key: 'stars' },
'★'.repeat( stars ),
( ( stars * 2 ) % 2 ) ? '½' : '' );
}
blocks.registerBlockType( 'stars/stars-block', {
@phillcoxon
phillcoxon / functions.php
Created August 2, 2017 05:29 — forked from TimBHowe/functions.php
WooCommerce - Add custom post_meta data to the order REST API response.
<?php
/**
* Hook into order API response to add custom field data.
*
* @param $order_data array
* @param $order WC_Order
* @param $fields array
* @param $server array
*
<?php
/*
This script will allow you to send a custom email from anywhere within wordpress
but using the woocommerce template so that your emails look the same.
Created by craig@123marbella.com on 27th of July 2017
Put the script below into a function or anywhere you want to send a custom email
*/
@vladimirsiljkovic
vladimirsiljkovic / select.css
Last active November 26, 2022 09:59
Cross-browser (IE11+) <select> element styling without wrapper <div> https://jsbin.com/diqene/edit?html,css,output
select {
-webkit-appearance: none; /* Webkit */
-moz-appearance: none; /* FF */
-ms-appearance: none; /* Edge */
appearance: none; /* Future */
/* Optional styles */
padding: 0.3em 1.5em 0.3em 0.6em;
border: 1px solid currentColor;
background: white;
@filipecsweb
filipecsweb / functions.php
Last active November 19, 2019 12:57
Remove order notes from WooCommerce checkout
<?php
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );