Skip to content

Instantly share code, notes, and snippets.

View mtx-z's full-sized avatar

Mtx Z mtx-z

View GitHub Profile
@mtx-z
mtx-z / woocommerce-update-product-loop-add-to-cart-button-template.php
Last active June 29, 2022 22:38
Update Woocommerce "add to cart" button HTML template from shop and product listing pages - override product loop add to cart button template
<?php
/**
* @snippet Change WooCommerce ‘Add to Cart’ button dispalyed in product listing page (home, shop, product lists)
* There is no overridable template file for this particular button displayed for product items add to cart button in product loops
* This hook allows to update the text or HTML of this button
* @source https://gist.github.com/mtx-z/90f7c35ff8714bdc533b5e7d5fbbe807
* @compatible WC 6.3.1
*/
add_filter('woocommerce_loop_add_to_cart_link', 'tx_woo_custom_list_add_to_cart_button', 10, 2);
@mtx-z
mtx-z / .htaccess
Last active February 15, 2023 11:17
Wordpress .htaccess with Header Caching + CSP Content Security Policy + Gzip compression + PHP execution protection + Spam protection (WIP)
#WP block - see https://fr.wordpress.org/support/article/htaccess/
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# ajouter un slash après /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
@mtx-z
mtx-z / wp-bootstrap5.0-pagination.php
Last active November 15, 2023 00:47
Wordpress 5.7 Bootstrap 5.0 pagination (with custom WP_Query() and global $wp_query support)
<?php
/**
* @param WP_Query|null $wp_query
* @param bool $echo
* @param array $params
*
* @return string|null
*
* Using Bootstrap 4? see https://gist.github.com/mtx-z/f95af6cc6fb562eb1a1540ca715ed928
*
@mtx-z
mtx-z / wp-woocommerce-allow-non-variation-attributes-frontend-selection.php
Last active October 31, 2024 16:58
Woocommerce: use non-variation attributes from frontend - allow customers to select term (option) from non-variation attributes on variable or simple products frontend pages, add selection to cart item, display it in cart, add it to order item
<?php
/**
* Inspired from: https://gist.github.com/dazecoop/548b2621e86fb030da8e5adb1bfe484f
*
* How to use:
* - add to your function.php or related
*
* What you can use it for:
* Variable products:
* - you have variable product with some attributes not used for variations
@mtx-z
mtx-z / wp-woocommerce-checkout-form-bootstrap4.4.php
Created December 11, 2019 11:16
Add bootstrap 4.4 styling to Woocommerce checkout shipping and billing form
<?php
/**
* Edit checkout form inputs
* source: https://gist.github.com/nickkuijpers/5d07ecf9b0a0678b4f4c
*/
add_filter('woocommerce_checkout_fields', 'addBootstrapToCheckoutFields' );
/**
* @param $fields
* @return mixed
*/
@mtx-z
mtx-z / wp5.3-boostrap4.4-collapse-navwalker.php
Last active August 12, 2021 16:48
Wordpress 5.3 NavWalker with Bootstrap 4.4 collapse with correct parent ".collapsed" class and ".active" classes (custom Wordpress nav walker class + example)
<?php
/**
* Class Name: Bootstrap_Collapse_NavWalker
* GitHub URI: https://gist.github.com/mtx-z/db34d68364108c0285e6e3e721630846
* Description: A custom WordPress 5.3 nav walker class for Bootstrap 4.4 nav menus in a custom theme using the WordPress built in menu manager
* Version: 0.1
* Author: Mtxz
* Source: https://github.com/filipszczepanski/wp-bootstrap4-collapse-navwalker
* Tested only with 1 sublevel, but should work with as many level as you want
@mtx-z
mtx-z / wp-woocommerce-edit-product-loop-thumbnail-template.php
Last active February 22, 2024 08:47
Woocommerce (3.8.1-6.2.2) edit product loop thumbnail template (allows to had/edit HTML outputted by Woocommerce to generate the product loop thumbnail image area, as there is no dedicated template file to override) - Wordpress / WooCommerce 3.8.1-6.2.2
<?php
/**
* Edit default Woocommerce product loop thumbnail template
* As there is no dedicated Woocommerce template (eg wp-content/plugins/woocommerce/templates/loop/price.php)
* because it's generated using filter, we must remove Woocommerce hook, and add our own "at the same place"
* to edit the product loop thumbnail template
* tested up to
* 14/07/2023 :
* Woocommerce 6.2.2
* 12/10/2020 :
@mtx-z
mtx-z / [nginx] laravel remove index.php from url
Last active February 11, 2021 19:43 — forked from slow-is-fast/laravel remove index.php from url.md
[nginx] laravel remove index.php from url
# Remove index.php$
if ($request_uri ~* "^(.*/)index\.php$") {
return 301 $1;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
# Remove from everywhere index.php
if ($request_uri ~* "^(.*/)index\.php(/?)(.*)") {
@mtx-z
mtx-z / acf-json-sage9.php
Created June 2, 2018 10:30
ACF-json with Roots Sage 9 - get_stylesheet_directory() point to theresources/ folder. From local JSON ACF documentation.
/**
* ACF save json folder
*/
add_filter( 'acf/settings/save_json', 'my_acf_json_save_point' );
function my_acf_json_save_point( $path ) {
return get_stylesheet_directory() . '/acf-json-custom-folder';
}
/**
@mtx-z
mtx-z / wordpres-various-removers.php
Created May 27, 2018 17:27
WordPress - various removers
<?php
/**
* Various removers
* todo: all may not be still needed/usefull/correct
*/
/**
* @param $headers
*