Skip to content

Instantly share code, notes, and snippets.

@wpserve
wpserve / in-stock-varitaions.php
Last active December 13, 2023 14:17
In stock product variations by default
<?php
/**
* THIS CODE IS NO LONGER WORKS
* PLEASE USE THE FILTER EVERYTHING PRO VERSION 1.7.15.6 OR ABOVE
*/
/**
* Makes only In stock products visible in filtering process
* You can put this code in the end of the functions.php file
* of your active theme
@wpserve
wpserve / price_fitler_taxex.php
Created March 6, 2023 11:18
Price filter with included taxes
<?php
// If prices include taxes
add_filter( 'wpc_set_num_shift', 'flrt_set_num_shift', 10, 2 );
function flrt_set_num_shift( $value, $entity_name ) {
if ( $entity_name === '_price' ) {
// Let's imagine that tax is 10%
// The final price will be
// $price_with_tax = $price + $price*0.1;
$value = $value + $value * 0.1;
}
@wpserve
wpserve / PostMetaNumEntity.php
Created April 14, 2022 12:13
PostMetaNumEntity.php v 1.6.5
<?php
namespace FilterEverything\Filter;
if ( ! defined('WPINC') ) {
wp_die();
}
class PostMetaNumEntity implements Entity
{
@wpserve
wpserve / RequestParser.php
Created April 13, 2022 09:32
Request parser v 1.6.5
<?php
namespace FilterEverything\Filter;
if ( ! defined('WPINC') ) {
wp_die();
}
class RequestParser
{
@wpserve
wpserve / wpc-helpers.php
Created April 12, 2022 15:26
WPC helpers v 1.6.5
<?php
if ( ! defined('WPINC') ) {
wp_die();
}
use \FilterEverything\Filter\Container;
use \FilterEverything\Filter\FilterSet;
use \FilterEverything\Filter\FilterFields;
use \FilterEverything\Filter\PostMetaNumEntity;
@wpserve
wpserve / move-seo-text-woocommerce.php
Created March 22, 2022 09:34
Move SEO text to bottom for WooCommerce
<?php
add_action('wp_head', 'wpc_add_filters_seo_description');
function wpc_add_filters_seo_description(){
if( class_exists( 'FilterEverything\Filter\Container' ) ){
$seoFrontEnd = FilterEverything\Filter\Container::instance()->getSeoFrontendService();
$your_new_hook = 'woocommerce_archive_description';
remove_action('woocommerce_after_shop_loop', [ $seoFrontEnd, 'showSeoDescription' ], 5);
add_action( $your_new_hook, [ $seoFrontEnd, 'showSeoDescription' ] );
@wpserve
wpserve / titles-instead-of-term-ids.php
Created March 10, 2022 16:12
ACF Title instead of term ids
<?php
add_filter('wpc_filter_post_meta_term_name', 'wpc_acf_tax_term_name', 10, 2);
function wpc_acf_tax_term_name($term_name, $e_name)
{ // tax_object - is a filter meta key name.
if( $e_name === 'tax_object' ){
$term = get_term( $term_name, 'product_cat' ); // product_cat is related taxonomy
$term_name = $term->name;
}
return $term_name;
@wpserve
wpserve / horizontal-filters-for-separate-filter-set.php
Last active February 23, 2022 13:50
Horizontal Filters for separate FIlter Set
<?php
add_action('wp_head', 'wpc_inline_filters');
function wpc_inline_filters(){
// Page IDs where this CSS should be displayed
if( is_page( array(2006, 2049) ) ):
?>
<style type="text/css">
@media screen and (min-width: 768px) {
.wpc-filter-set-2058 .wpc-filters-widget-wrapper,
<?php
// Checkbox filters brand images
add_filter( 'wpc_filters_checkbox_term_html', 'wpc_term_brand_custom_logo', 10, 4 );
// Radio filters brand images
add_filter( 'wpc_filters_radio_term_html', 'wpc_term_brand_custom_logo', 10, 4 );
function wpc_term_brand_custom_logo($html, $link_attributes, $term, $filter)
{
$img = '';
@wpserve
wpserve / functions.php
Last active April 29, 2021 10:04
Modifying WordPress Loop for Custom Tax
<?php
add_action( 'pre_get_posts', 'stepasyuk_custom_wp_query' );
function stepasyuk_custom_wp_query( $wp_query ){
if( $wp_query->is_main_query() && $wp_query->is_tax('categories-formations') ){
$wp_query->set('posts_per_page', -1);
$wp_query->set('orderby', 'date');
$wp_query->set('order', 'DESC');
}
}