Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Gibbs mgibbs189

View GitHub Profile
@mgibbs189
mgibbs189 / functions.php
Last active Nov 23, 2020
Enfold - fix product quantity buttons on refresh
View functions.php
<?php
// Add to your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$(document).trigger('updated_cart_totals'); // fix the "+/-" quantity buttons
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'term_link', function( $termlink, $term, $taxonomy ) {
if ( 'portfolio_skills' == $taxonomy ) { /* TODO: this taxonomy name may need to change? */
$termlink = '/wineries-2/?_wine_types=' . $term->slug;
}
return $termlink;
}, 10, 3);
@mgibbs189
mgibbs189 / functions.php
Created Nov 12, 2020
Automatically expand all top-level terms
View functions.php
<?php
// Add to your (child) theme's functions.php file
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.facetwp-facet-product_categories > .facetwp-checkbox .facetwp-expand').each(function() {
View test.php
<?php
// Add the following into your (child) theme's functions.php
add_action( 'wp_head', function() {
?>
<script>
(function($) {
$(document).on('facetwp-loaded', function() {
$('.fwpl-item.titleemail a').each(function() {
@mgibbs189
mgibbs189 / functions.php
Created Oct 27, 2020
FacetWP - checkbox facet to show posts with images
View functions.php
<?php
add_filter( 'facetwp_index_row', function( $params, $class ) {
if ( 'has_image' == $params['facet_name'] ) {
$post_id = (int) $params['post_id'];
if ( has_post_thumbnail( $post_id ) ) {
$params['facet_value'] = 1;
$params['facet_display_value'] = 'Has photos';
}
@mgibbs189
mgibbs189 / test.js
Created Oct 23, 2020
FacetWP - ignore URL hash except when resetting
View test.js
<script>
(function($) {
$(document).on('facetwp-refresh', function() {
if (! FWP.loaded) {
FWP.temp_set_hash = FWP.set_hash; // on init, save a backup of FWP.set_hash()
}
if (FWP.is_reset) {
FWP.set_hash = FWP.temp_set_hash; // on reset, store FWP.set_hash()
}
else {
@mgibbs189
mgibbs189 / functions.php
Created Oct 19, 2020
FacetWP - translate "On sale" text
View functions.php
<?php
add_filter( 'gettext', function( $translated_text, $text, $domain ) {
if ( 'fwp-front' == $domain && 'On Sale' == $translated_text ) {
$translated_text = 'On Sale (other language)';
}
return $translated_text;
}, 10, 3 );
@mgibbs189
mgibbs189 / functions.php
Last active Oct 19, 2020
FacetWP - ignore WC REST API queries
View functions.php
<?php
// Add to your (child) theme's functions.php
// woocommerce_rest_{$this->post_type}_object_query
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( false !== strpos( $_SERVER['REQUEST_URI'], 'wp-json/wc/v3' ) ) {
$is_main_query = false;
}
return $is_main_query;
@mgibbs189
mgibbs189 / functions.php
Created Oct 9, 2020
FacetWP - ignore any query using "showposts"
View functions.php
<?php
// Add to your (child) theme's functions.php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( false !== $query->get( 'showposts', false ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@mgibbs189
mgibbs189 / functions.php
Last active Oct 6, 2020
FacetWP - sort by menu_order for certain post type
View functions.php
<?php
// Add to your (child) theme's functions.php
add_action( 'pre_get_posts', function( $query ) {
if ( 'providers' == $query->get( 'post_type' ) ) {
$query->set( 'orderby', [ 'menu_order' => 'ASC', 'date' => 'DESC' ] );
}
});
You can’t perform that action at this time.