Skip to content

Instantly share code, notes, and snippets.

View DavidCramer's full-sized avatar

David Cramer DavidCramer

View GitHub Profile
@DavidCramer
DavidCramer / output
Created December 6, 2016 09:51 — forked from mikeTierney19/output
changing $output
function my_facetwp_facet_html( $output, $params ) {
if ( 'monthly_tags' == $params['facet']['name'] ) {
$output = '
<div class="facetwp-checkbox" data-value="january-2017">
January 2017
<span class="facetwp-counter">(1)</span>
</div>
<div class="facetwp-checkbox" data-value="february-2017">
February 2017
<span class="facetwp-counter">(1)</span>
function my_facetwp_index_row( $params, $class ) {
if ( 'branch' == $params['facet_name'] ) {
$values = (array) $params['facet_value']; // an array of post IDs (it's already unserialized)
foreach ( $values as $val ) {
$params['facet_value'] = the_field( 'martygeocoderlatlng', $val );
$params['facet_display_value'] = the_field('martygeocoderaddress', $val);
$class->insert( $params ); // insert each value to the database
}
// skip the default indexing query
return false;
@DavidCramer
DavidCramer / custom.js
Last active February 6, 2017 05:57 — forked from mgibbs189/test.js
FacetWP - Set "sort by" when specific facet is used
(function($) {
$(document).on('facetwp-refresh', function() {
if( FWP.extras['sort'] !== 'default' ){
return;
}
if ( FWP.facets['baby_sitter_cost'].length ) {
FWP.extras['sort'] = 'cost';
}else if ( FWP.facets['age'].length ) {
FWP.extras['sort'] = 'age';
}else if ( FWP.facets['experience'].length ) {
function cspm_display_single_product_map(){
echo do_shortcode('[facetwp map="true"]');
}
add_action('woocommerce_after_single_product_summary', 'cspm_display_single_product_map', 15);
<?php
/**
* The template for displaying product content in the single-product.php template
*
* Override this template by copying it to yourtheme/woocommerce/content-single-product.php
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
@DavidCramer
DavidCramer / functions.php
Created February 21, 2017 05:16
Disable mouse scroll on Map
<?php
// add this to your child themes functions.php file
add_filter( 'facetwp_map_init_args', function ( $args ) {
$args['scrollwheel'] = false;
return $args;
} );
@DavidCramer
DavidCramer / functions.php
Last active February 22, 2017 07:30
Exclude administrators from DB Post Types users connection
<?php
// Add the code below to your functions.php file of your child theme.
// This removes all users that are administrators from being synced in DB Post Types
// Uses the `dbpt_source_exclude-{$slug}` filter
add_filter( 'dbpt_source_exclude-users', function () {
// return the ID's of users NOT to be synced.
return get_users( array(
'role__in' => array( 'administrator' ),
@DavidCramer
DavidCramer / template.php
Last active February 22, 2017 12:59
Single Product Location
<?php
// create a new FacetWP template called 'Products'
// Then place all this code in the "Query Arguments"
// Leave "Display Code" empty
// in your single product template use the shortcode [facetwp template="product" map="true"]
if( !empty( $_POST['data']['http_params']['uri'] ) ){
$product_id = url_to_postid( $_POST['data']['http_params']['uri'] );
}else{
$product_id = get_queried_object_id();
@DavidCramer
DavidCramer / functions.php
Created February 22, 2017 13:15
FacetWP - FSelect Search placeholder text
<?php
// Add the code below to your child themes functions.php file
add_filter( 'gettext', function( $translated_text, $text, $domain ) {
if ( 'fwp' == $domain ) {
if ( 'Search' == $translated_text ) {
$translated_text = 'The new placeholder'; // Add your placeholder here
}
}
@DavidCramer
DavidCramer / functions.php
Created February 23, 2017 12:41
Alter selectable values for a facet
<?php
// add the below code to your child themes functions.php file.
// Read the comments below on what to change
function fwps_modify_selectable_values( $args ) {
// change my_facet with the facet you want to alter
if ( 'my_facet' == $args['facet']['name'] ) {
// add and remove the slugs of the items you want to exclude
$exclude = array(