Skip to content

Instantly share code, notes, and snippets.

View nicomollet's full-sized avatar

Nico Mollet nicomollet

View GitHub Profile
@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 / 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 / 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 / gtm4wp-exclude-failed-orders.php
Created August 28, 2018 07:14
Google Tag Manager for WordPress (DuracellTomi): Exclude orders with status failed
<?php
/**
* Google Tag Manager: Exclude orders with status failed (only paid statuses)
*
* @param $tag
*
* @return string
*/
function googletagmanager_getthetag( $tag ) {
global $wp;
@nicomollet
nicomollet / acf-disable-autocomplete.php
Created July 26, 2018 15:03
ACF Disable Autocomplete on input and textarea fields
<?php
/**
* ACF Disable Autocomplete on input and textarea fields
* Chrome ignores autocomplete="off" in some cases
*
* @author Nicolas Mollet
* @link https://bugs.chromium.org/p/chromium/issues/detail?id=468153
*/
function acf_input_disable_autocomplete() {
@nicomollet
nicomollet / woocommerce-price-multisite.php
Created April 23, 2018 08:06
WooCommerce Product Price Shortcode, compatible with multisite
<?php
/**
* WooCommerce Product Price Shortcode Compatible with Multisite
* Example: [woocommerce_price_multisite id="6452" site="6"]
*
* @param $atts
*
*/
function woocommerce_price_multisite( $atts ) {
@nicomollet
nicomollet / private_posts_search_resultats.php
Last active October 28, 2020 22:47
WordPress: display private posts in search results if user has permission
<?php
/**
* Search results: display private posts if user has permission
*
* @param WP_Query $query
*/
function custom_private_posts_earch_results( $query ) {
if ( current_user_can( 'read_private_posts' ) ) {
if ( $query->is_search() && $query->is_main_query() ) {
$query->set( 'post_status', [ 'publish', 'private' ] );
@nicomollet
nicomollet / email_order_items_product_description.php
Last active April 23, 2018 08:00
WooCommerce Order Email: Each Item with product description
<?php
add_action( 'woocommerce_order_item_meta_start', 'custom_order_email_product_description', 10, 4 );
function custom_order_email_product_description( $item_id, $item, $order, $plain_text = '' ){
$item_data = $item->get_data();
$product = wc_get_product($item_data['product_id'] );
$product_short_description = $product->get_short_description();
$product_description = $product->get_description();
if ( ! empty( $product_short_description ) ) {
@nicomollet
nicomollet / polylang-langswitcher-shortcode.php
Last active April 16, 2025 15:26
Polylang shortcode for lang switcher
<?php
/**
* Polylang Shortcode - https://wordpress.org/plugins/polylang/
* Add this code in your functions.php
* Put shortcode [polylang_langswitcher] to post/page for display flags
*
* @return string
*/
function custom_polylang_langswitcher() {
$output = '';
@nicomollet
nicomollet / polylang-display-post-states-language.php
Last active January 18, 2018 10:08
Polylang: Display a country flag or the name of the language as a "post state" in post lists
<?php
/**
* Polylang: Display a country flag or the name of the language as a "post state"
*
* @param array $post_states An array of post display states.
* @param \WP_Post $post The current post object.
*
* @return array A filtered array of post display states.
*/
function polylang_display_post_states_language( $post_states, $post ) {