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 / wp-woocommerce-allow-non-variation-attributes-frontend-selection.php
Last active March 14, 2025 08:38
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-bootstrap5.0-pagination.php
Last active March 28, 2025 13:31
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 / .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 / 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);