Skip to content

Instantly share code, notes, and snippets.

View Micemade's full-sized avatar

Micemade Micemade

View GitHub Profile
@Micemade
Micemade / micemade-wp-cli-delete-before.php
Last active July 21, 2024 19:37
WP CLI command for deleting old posts (and CPT's)
<?php
function micemade_wpcli_delete_before( $args, $assoc_args ) {
// If arguments array is empty, or if there aren't exactly 5 items, show error notice.
if ( empty( $args ) || count( $args ) !== 5 ) {
WP_CLI::error( __( 'Parameters: POST TYPE, POST STATUS, YEAR, MONTH and DAY are required (in this exact order). Please check your parameters. Command syntax is: wp delete-before <post_type> <post_status> <year> <month> <day> < --number=100 > < --date=post_date >.', 'micemade-fse-store' ) );
return;
}
$post_type = $args[0];
@Micemade
Micemade / woocommerce-cart-item-coupon-price.php
Last active May 10, 2024 03:17
WooCommerce display price with applied coupon(s) per item in cart
<?php
/**
* Woocommerce cart - display prices with coupons applied, per cart item.
*
* @param string $subtotal
* @param array $cart_item
* @param string $cart_item_key
* @return $subtotal
*
* Inspired by:
@Micemade
Micemade / woocommerce_unassign_variation_to_attribute.php
Last active April 7, 2019 22:18
Un-assign "Used for variations" from WooCommerce product attribute if the "pa_size" attribute is "Universal size"
<?php
/**
* Un-assign "Used for variations" from product attribute
* if the "pa_size" attribute is "Universal size"
* because of possible multiple version of universal sizes,
* we search the attribute which slug starts with a "uni"
*/
function unassign_variation_to_attribute() {
@Micemade
Micemade / content-product-action-priorities.php
Created March 2, 2019 21:46
Change priorities of WooCommerce template "content-product.php". Using global $wp_filter.
<?php
/**
* Change priority of hooked functions in "content-product.php"
*
* @return void
*/
function wc_content_product_priorities() {
global $wp_filter;
@Micemade
Micemade / plugin-load-priority.php
Created March 2, 2019 21:21
Change plugin load order (prioritize it) by shifting it to first place in array of active plugins.
<?php
/**
* Plugin (WooCommerce) loads first
*
* @return void
* make sure plugin (WooCommerce) is loaded before any other,
* this was created because of hook priority issues.
*/
function prefix_load_plugin_first() {
// Get all active plugins from options.
<?php
/**
* FILTER WIDGETS IN WP ADMIN
* assuming you already enqueued some of your js / css in WP admin ( customAdminCode() ) :
* include (or separately enqueue) this jQuery plugin - https://github.com/cheeaun/jquery.livefilter
* all code (php,js,css) is here, but you should separate it, off course ... ;)
*/
function customAdminCode() {
wp_register_script('my-admin-js', get_template_directory_uri(). '/js/admin/admin.js');
<?php
/**
* CUSTOM WP NAV MENU - no walker
*
* @package WordPress
* @subpackage My theme
*
* @details custom replacement menu for wp_nav_menu()
* with a "little" help from :
* David Baker - https://dtbaker.net/