Skip to content

Instantly share code, notes, and snippets.

@igorbenic
igorbenic / coupon_filter.php
Last active November 24, 2021 20:48
How to manage Order Item Data in WooCommerce | https://www.ibenic.com/manage-order-item-meta-woocommerce
<?php
// WC_Checkout
/**
* Add coupon lines to the order.
*
* @param WC_Order $order Order instance.
* @param WC_Cart $cart Cart instance.
*/
@kierzniak
kierzniak / functions.php
Created February 28, 2018 10:02
Redirect posts with old permalink structure to new links.
<?php
/**
* Redirect posts with old permalink structure to new links.
*
* If you change your posts permalink structure you should redirect all
* trafic from old permalink to new one. This script will redirect posts
* from /%postname%/ to current post link using 301 status.
*
* This script is working only for /%postname%/ => current link
@ControlledChaos
ControlledChaos / .maintenance
Last active March 30, 2023 21:59 — forked from mikemanger/.maintenance
Example WordPress .maintenance file. maintenance.php is optional but useful for styling the message the public will see (it is also used when updating WordPress components), drop it in your wp-content folder.
<?php
function is_user_logged_in() {
$loggedin = false;
foreach ( (array) $_COOKIE as $cookie => $value ) {
if ( stristr( $cookie, 'wordpress_logged_in_' ) ) {
$loggedin = true;
}
}
return $loggedin;
}
@TimBHowe
TimBHowe / functions.php
Created March 8, 2016 17:54
Forcibly remove the tax line item and calculation from the cart. (suggest just using the GEO setting in WooCommerce)
<?php
// Remove the Tax Line item from the cart.
function wc_remove_cart_tax_totals( $tax_totals, $instance ) {
if( is_cart() ) {
$tax_totals = array();
}
return $tax_totals;
}
@carlodaniele
carlodaniele / food-example-plugin.php
Last active August 22, 2021 09:00
An example plugin for WPMU DEV readers
<?php
/**
* @package Food_example_plugin
* @version 1.0
*/
/*
Plugin Name: Food example plugin
Plugin URI: http://wordpress.org/extend/plugins/#
Description: This is an example plugin for WPMU DEV readers
Author: Carlo Daniele
@quasel
quasel / acf-fields.php
Created December 28, 2015 19:36 — forked from hereswhatidid/acf-fields.php
Create custom product details tabs within WooCommerce using an ACF (Advanced Custom Fields) Repeater field.
<?php
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'acf_product_options',
'title' => 'Product Options',
'fields' => array (
array (
'key' => 'acf_product_options_tabbedcontent_label',
'label' => 'Tabbed Content',
@paulcollett
paulcollett / functions.php
Last active December 19, 2023 04:42
Remove Yoast HTML Comments “This site is optimized with the Yoast WordPress SEO plugin”
// For Yoast SEO Plugin Version: 14.1+ add to your Wordpress Theme's functions.php...
// Remove All Yoast HTML Comments
// https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
// Credit @devendrabhandari (https://gist.github.com/paulcollett/4c81c4f6eb85334ba076#gistcomment-3303423)
add_filter( 'wpseo_debug_markers', '__return_false' );
// For Yoast SEO Plugin Version: < 14.1 add to your Wordpress Theme's functions.php...
@TimBHowe
TimBHowe / remove_orders
Last active January 31, 2017 12:47
Remove all orders from WordPress WooCommerce. This is ideally for clearing out orders on a staging/beta version of a WooCommerce site where the order information is not needed or should not be stored.
DELETE FROM wp_postmeta
WHERE post_id IN(SELECT ID FROM wp_posts WHERE post_type = 'shop_order');
DELETE FROM wp_posts WHERE post_type = 'shop_order';
@phpmaps
phpmaps / list_terms_exclusions
Created February 6, 2015 06:32
list_terms_exclusions plugin
<?php
/*
Plugin Name: Pancake v. 1.1
Plugin URI: http://phpmaps.github.io/me/
Description: Hides wordpress categories that Johnny finds annoying when working in the admin!
Version: 1.1 rev 1 (Sea Gull)
Author: Doogs
Author URI: http://phpmaps.github.io/me/
*/
@lmartins
lmartins / functions.php
Last active November 3, 2023 19:28 — forked from woogist/functions.php
By default WooCommerce redirects the user to the My Account page after a successful login. You may change this and use a custom URL based on the user role, like the Dashboard for admins and My Account page for customers. To do this, add this code at the end of the file functions.php located in wp-content/themes/your-theme-name/ https://support.w…
<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user