Skip to content

Instantly share code, notes, and snippets.

View nicomollet's full-sized avatar

Nico Mollet nicomollet

View GitHub Profile
@nicomollet
nicomollet / elementor-template-polylang-translation.php
Created September 17, 2018 12:44
Elementor get polylang translation of template
<?php
/**
* Elementor get polylang translation of template
*/
add_filter( 'elementor/theme/get_location_templates/template_id', function( $post_id ) {
if(!is_admin()){
if ( function_exists( 'pll_get_post' ) ) {
@nicomollet
nicomollet / polylang-elementor-conditions-compatibility.php
Last active September 10, 2019 14:12
Fix for Elementor template conditions not compatible with polylang (you need to save again one of your templates to make it work, after putting this function in your plugin/theme). Needs to be priority 1
<?php
/**
* Fix for Elementor template conditions not compatible with Polylang (you need to save again one of your templates to make it work, after putting this function in your plugin/theme)
* Needs to be priority 1, since Polylang uses the action parse_query which is fired before pre_get_posts
*
* @link https://github.com/polylang/polylang/issues/152#issuecomment-320602328
*
* @param WP_Query $query
*/
function polylang_elementor_library_conditions_parse_query( $query ) {
@nicomollet
nicomollet / custom-name-your-price-in-product-name.php
Last active October 31, 2018 17:00
Product Open Pricing plugin: Customize Product Name with Price
<?php
/**
* Product Open Pricing plugin: Customize Product Title with Price
*
* @param WC_Cart $cart
*/
function custom_woocommerce_before_calculate_totals( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
@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.
@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 / 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 / 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 / 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_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 / 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){