Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
hereswhatidid / acf-sample-options.php
Last active April 22, 2019 10:35
Set correct language for ACF options pages with custom post_id
<?php
class ACF_SampleOptions_Page {
static $slug = 'sample_options_slug';
static $post_id = 'sample_options_id';
public static function init() {
@hereswhatidid
hereswhatidid / wp-sortable-column.php
Last active October 18, 2017 13:57
Add a custom, sortable column to a WordPress post type admin table
<?php
class HWID_Post_Sortable {
static $post_type_slug = 'post';
static function init() {
add_action( 'manage_' . self::$post_type_slug . '_posts_custom_column', array(
'HWID_Post_Sortable',
'sort_column_display',
@hereswhatidid
hereswhatidid / example-usage.php
Last active September 8, 2017 16:57
Plugin for adding any field as an attribute to the WooCommerce CSV import
<?php
function hwid333_add_custom_attribute_columns( $fields ) {
$fields[] = array(
'slug' => 'shirt-size',
'name' => 'Shirt Size', // This is the name of the column in the CSV
);
$fields[] = array(
@hereswhatidid
hereswhatidid / custom-package-name.php
Created October 18, 2016 13:48
Create custom shipping packages and manually set their display names in WooCommerce
<?php
add_filter( 'woocommerce_shipping_package_name', 'rmg_package_names', 10, 3 );
function rmg_package_names( $package_name, $i, $package ) {
if ( ! empty( $package['name'] ) ) {
$package_name = $package['name'];
}
@hereswhatidid
hereswhatidid / roundup-shipping.php
Created September 9, 2016 13:21
This snippet will round up all shipping rates in a WooCommerce store.
<?php
add_filter( 'woocommerce_package_rates', 'roundup_rates', 10, 2 );
function roundup_rates( $rates, $package ) {
foreach( $rates as $key => $rate ) {
$rates[$key]->cost = ceil( $rate->cost );
}
return $rates;
}
<?php
class ACF_Product_Options {
static $slug = 'hwid_attributes';
public static function init() {
// Gather the global attribute types
$attribute_terms = wc_get_attribute_taxonomy_names();
@hereswhatidid
hereswhatidid / retina-media-query.css
Created May 9, 2016 19:48
Retina-specific media query
@media(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
/* Retina-specific stuff here */
}
@hereswhatidid
hereswhatidid / admin-variation-skus.js
Created May 4, 2016 15:53
Show variation SKUs on the Product admin screen for WooCommerce
jQuery( document ).ready( function() {
jQuery( '#woocommerce-product-data' ).on( 'woocommerce_variations_loaded', function() {
var $panels = jQuery( this ).find( '.woocommerce_variation' );
$panels.each( function() {
var sku = jQuery( this ).find( '.sku input' ).val();
if ( sku ) {
jQuery( this ).find( 'h3 > strong' ).text( 'SKU: ' + sku );
}
} );
@hereswhatidid
hereswhatidid / email.php
Last active February 12, 2016 14:23
ACF field generation code.
<?php
array (
'key' => 'field_56bde9a0ea676',
'label' => 'Email',
'name' => 'email',
'type' => 'email',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
@hereswhatidid
hereswhatidid / custom-acf-wysiwyg-css.php
Last active September 27, 2022 15:27
Applies defined CSS classes to the ACF WYSIWYG editor so that you can individually style them.
<?php
function hwid_acf_admin_footer() {
?>
<script>
( function( $) {
acf.add_filter( 'wysiwyg_tinymce_settings', function( mceInit, id ) {
// grab the classes defined within the field admin and put them in an array
var classes = $( '#' + id ).closest( '.acf-field-wysiwyg' ).attr( 'class' );