Skip to content

Instantly share code, notes, and snippets.

@shirokoweb
shirokoweb / functions.php
Created November 30, 2019 18:58
WordPress shutdown hook to disable WooCommerce get_refreshed_fragments
<?php
/** Disable Ajax Call from WooCommerce on front page, posts, categories, and tags*/
add_action( 'shutdown', 'dequeue_woocommerce_cart_fragments');
function dequeue_woocommerce_cart_fragments() {
if (is_front_page() || is_single() || is_category() || is_tag() ) wp_dequeue_script('wc-cart-fragments');
}
@shirokoweb
shirokoweb / functions.php
Created November 30, 2019 18:56
Remove WooCommerce resources where it's not needed
<?php
add_action( 'wp_enqueue_scripts', 'optimize_woocommerce_styles_scripts', 99 );
function optimize_woocommerce_styles_scripts() {
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
if ( function_exists( 'is_woocommerce' ) ) {
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
@shirokoweb
shirokoweb / widget.html
Created November 30, 2019 08:43
Unlimited Elements - Edit Widget - ACF repeater
<div class="wrapper">
{% for item in current_post.cf_module %}
<div class="left-col-img">
<img src="{{item.image_module|raw}}" alt="image alt here">
</div>
<div class ="right-col-content">
<h3>{{item.titre_du_module|raw}}</h3>
<p>{{item.description_du_module|raw}}</p>
@shirokoweb
shirokoweb / functions.php
Created July 18, 2019 16:17
Mode vacances WooCommerce
<?php
// Mode vacances
add_action ('init', 'mode_vacances_boutique');
// Désactiver les fonctionnalités de WC
function mode_vacances_boutique() {
// Désactiver l'ajout au panier
@shirokoweb
shirokoweb / functions.php
Last active June 2, 2019 21:34
Remplacer des chaînes de texte WooCommerce
<?php
// Remplacer "Lire la suite" par autre chose
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
function custom_woocommerce_product_add_to_cart_text( $text ) {
// En utilisant une condition (if)
if ( 'Lire la suite' == $text ) {
$text = __( 'Commander', 'woocommerce' );
}
@shirokoweb
shirokoweb / randomproducts.php
Created May 3, 2019 11:05
Random simple product generation for benchmarking
<?php
/*
DISCLAIMER :
This script is for BENCHMARK, use at your own risk.
DO NOT run this script unless you FULLY understand and know what you are doing.
This script will generate random 1M simple products on your WooCommerce (can be modified @line 43)
*/
if (php_sapi_name() !== 'cli') {
@shirokoweb
shirokoweb / .wpauth
Created March 25, 2019 18:29
auth wp-admin / login
uname:pwdmd5hash
# BEGIN WP AUTH
<Files wp-login.php>
AuthUserFile /var/www/vhosts/hostname.com/httpdocs/.wpauth
AuthName "Authentication"
AuthType Basic
require valid-user
</Files>
@shirokoweb
shirokoweb / Translate-a-String-in-WooCommerce.php
Created February 16, 2019 09:18
Translate a String in WooCommerce
add_filter( 'gettext', 'webplus_translate_woocommerce_strings', 999 );
function webplus_translate_woocommerce_strings( $translated ) {
// Store all string in an array
$translatedStrings = array(
'Sale!' => 'ON OFFER',
'Product Description' => 'Product Specifications',
);
$translated = str_ireplace( array_keys($translatedStrings), $translatedStrings, $translated );
return $translated;
}
@shirokoweb
shirokoweb / index.php
Created May 28, 2018 14:45
hide redirection URLS
<?php
$id = isset( $_GET['id'] ) ? rtrim( trim( $_GET['id'] ), '/' ) : 'default';
$f = fopen( 'redirects.txt', 'r' );
$urls = array();
// The file didn't open correctly.
if ( !$f ) {
echo 'Make sure you create your redirects.txt file and that it\'s readable by the redirect script.';
die;
@shirokoweb
shirokoweb / webplus-plugin-filter.php
Created May 7, 2018 17:59
Exclure un plugin WordPress de certaines pages
<?php
// parse_url renvoie le chemin d'accès de l'URL demandée
$request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
// strpos trouve la position de la première occurrence de'/wp-admin/'
// et retourne false si la chaîne n'est pas trouvée.
// La variable $is_admin stocke la valeur retournée.
$is_admin = strpos($request_uri, '/wp-admin/');