Skip to content

Instantly share code, notes, and snippets.

View nicomollet's full-sized avatar

Nico Mollet nicomollet

View GitHub Profile
@nicomollet
nicomollet / woocommerce_paymentonsite_icon.php
Created November 24, 2020 08:20
WooCommerce: customize "payment on site" icon
<?php
/**
* WooCommerce Gateway Icon for "Payment On Site"
*
*
* @param string $icon The icon html markup
*
* @return string
*/
@nicomollet
nicomollet / woocommerce-local-pickup-only.php
Last active June 9, 2023 12:52
WooCommerce: hide shipping when products marked as "local pickup only" are in the cart
<?php
/**
* WooCommerce: hide shipping when products marked as "local pickup only" are in the cart
* Tested with WordPress 5.3.4 and WooCommerce 4.2.0
*
* The shipping class "local-pickup-only" needs to be created first.
* Then assign the products that are have "local pickup only" to this class
*
* @param array $rates
* @param array $package
@nicomollet
nicomollet / wpseo-schema-webpage.php
Last active June 9, 2023 12:51
Yoast Schema: Remove datePublished on WebPage
<?php
/**
* Yoast Schema: Remove datePublished on WebPage
*
* @param array $schema
*
* @return mixed
*/
function custom_wpseo_schema_webpage( $schema ) {
@nicomollet
nicomollet / wpseo_schema_organization.php
Last active June 9, 2023 12:51
Yoast SEO Organization Schema Replaced By LocalBusiness
<?php
/**
* Add LocalBusiness to schema Organization
*
* @api array $data The graph piece to filter.
*
* @return array
*/
function custom_wpseo_schema_organization($data){
@nicomollet
nicomollet / woocommerce_structured_data_product_brand.php
Created May 1, 2019 08:41
WooCommerce: Adds Brand attribute to "Product" Structured Data
<?php
/**
* WooCommerce: Adds Brand attribute to "Product" Structured Data
*
* @param array $data
*
* @return array
*/
function woocommerce_structured_data_product_brand ($data) {
global $product;
@nicomollet
nicomollet / woocommerce_remove_my_memberships_table.php
Last active April 16, 2019 10:01
WooCommerce Memberships, removes the "My Memberships" table from my account area
<?php
function woocommerce_remove_my_memberships_table() {
if ( function_exists( 'wc_memberships' )
&& method_exists( wc_memberships(), 'get_frontend_instance' )
&& method_exists( wc_memberships()->get_frontend_instance(), 'get_members_area_instance' )
) {
remove_filter( 'woocommerce_account_menu_items',
array( wc_memberships()->get_frontend_instance()->get_members_area_instance(), 'add_account_members_area_menu_item' ), 999 );
}
}
@nicomollet
nicomollet / woocommerce-sales-empty-cache.php
Created December 7, 2018 08:22
WooCommerce Scheduled Sales: everyday, sales start, cache should be emptied (WP Rocket)
<?php
/**
* WooCommerce Scheduled Sales: everyday, sales start, cache should be emptied (WP Rocket)
*
* @since 1.0.9
*/
function woocommerce_scheduled_sales_empty_wprocket_cache(){
// Clear WP Rocket Cache (whole site)
if ( function_exists( 'rocket_clean_domain' ) ) {
@nicomollet
nicomollet / export-users-with-meta.sql
Created November 21, 2018 15:47
Export WordPress users with meta
SELECT
t1.ID, t1.user_email,
MAX(CASE WHEN t2.meta_key = 'first_name' THEN meta_value END) AS first_name,
MAX(CASE WHEN t2.meta_key = 'last_name' THEN meta_value END) AS last_name,
MAX(CASE WHEN t2.meta_key = 'paying_customer' THEN meta_value END) AS paying_customer,
MAX(CASE WHEN t2.meta_key = 'billing_title' THEN meta_value END) AS billing_title
FROM th_users AS t1
INNER JOIN th_usermeta AS t2 ON t1.ID = t2.user_id
GROUP BY t1.ID, t1.user_email
@nicomollet
nicomollet / count-metakeysinpostmeta.sql
Created November 7, 2018 08:40
WordPress postmeta table, count uses of meta_keys
SELECT meta_key, COUNT(*) FROM wp_postmeta GROUP BY meta_key ORDER BY COUNT(*) DESC
@nicomollet
nicomollet / data-removal-confirmation-recipient.php
Last active November 5, 2018 11:00
WordPress Data Request/Removal Tool email confirmation recipient
<?php
/**
* Filters the recipient of the data request confirmation notification.
*
* In a Multisite environment, this will default to the email address of the
* network admin because, by default, single site admins do not have the
* capabilities required to process requests. Some networks may wish to
* delegate those capabilities to a single-site admin, or a dedicated person
* responsible for managing privacy requests.