Skip to content

Instantly share code, notes, and snippets.

View carmoreira's full-sized avatar

Carlos Moreira carmoreira

View GitHub Profile
@carmoreira
carmoreira / autovisible.js
Created July 3, 2019 16:53
start autoscroll only when visible - Logos Showcase - will only work with one slider in the page.
document.addEventListener('DOMContentLoaded', function () {
ls_curr_slider[0].stopAuto();
});
// this is the target which is observed
var target = document.querySelector('.lshowcase-logos');
// configure the intersection observer instance
var intersectionObserverOptions = {
root: null,
@carmoreira
carmoreira / personality-random.js
Created July 22, 2019 09:37
apply random value to answers in personality quiz
jQuery('.advq_question_container').first().find('input').each(function(){
var rule = JSON.parse( jQuery(this).attr('data-rule') );
var keys = Object.keys(thisrule);
rule[keys[ keys.length * Math.random() << 0]] = Math.ceil( Math.random() * 1000 ).toString();
jQuery(this).attr('data-rule', JSON.stringify(rule));
});
@carmoreira
carmoreira / advqfilter.php
Created July 23, 2019 13:57
Advisor Quiz: add ACF fields to the Query Filter for WooCommerce Products
/**
* Add custom fields to WooCommerce Products Query filter in Advisor Quiz
*
* @param [array] $fields array
* @return [array] $fields with included acf fields
*/
function advq_add_woo_acf( $fields ) {
// get acf groups for products
$groups = acf_get_field_groups(array('post_type' => 'product'));
@carmoreira
carmoreira / customaria.js
Last active August 5, 2019 15:02
Custom Aria Label for Interactive Map
function iwm_callback() {
// set aria label
document.querySelector('.iwm_map_canvas svg').setAttribute('aria-label','This is an interactive map.');
}
@carmoreira
carmoreira / meta.php
Last active August 28, 2019 14:19
metafields declaration format
$model['meta'] = [
'my_metabox_01' => [
'title' => 'Title',
'position' => 'normal',
'priority' => 'high',
'sections' => [
'info' => [
'title' => 'Title Info',
'desc' => 'description',
'icon' => 'dashicon',
@carmoreira
carmoreira / hashurl.js
Last active September 2, 2019 09:56
simulate click on filter based on hash from URL
jQuery(document).ready(function(){
var thishash = window.location.href.slice(window.location.href.indexOf('#') + 1);
var menuitem = jQuery('ul#tts-isotope-filter-nav li:contains("'+decodeURI(thishash)+'")');
if(thishash.length && menuitem.length){
menuitem.click();
}
});
@carmoreira
carmoreira / filter.php
Created September 10, 2019 10:44
custom order for fields in table layout for team showcase
add_filter( 'tshowcase_table_content_order', 'mycustom_table_content_order' );
function mycustom_table_content_order( $tshowcase_fields ) {
$ts_content_order = array(
1 => 'title',
2 => 'groups',
3 => 'taxonomy',
4 => 'ctaxonomy',
5 => 'dtaxonomy',
6 => 'position',
@carmoreira
carmoreira / addcpt.php
Created September 18, 2019 18:03
add cpt to available cpt options in advisor quiz
// Create Arrays to populate Query Builder with all available post types
add_filter( 'advq_admin_build_quiz', 'advq_coupon_cpt' );
function advq_coupon_cpt( $queryfields ) {
$fields = array();
$fields['label'] = 'Coupon';
// search
@carmoreira
carmoreira / advqext.js
Last active October 13, 2019 20:43
custom code for scrapper and hide/show
/* Rearrange fields order */
jQuery(document).ready(function(){
jQuery('.advq_askemail').insertBefore('.advq_askinfo_2');
});
/* Event triggered when we arrive at email form */
jQuery(".advq_quiz_wrap").on("advqEmailScreen", function() {
jQuery(".advq-hide-at-results").hide();
jQuery(".advq-show-at-results").show();
});
@carmoreira
carmoreira / filter.php
Created October 15, 2019 14:42
Advisor Quiz - add content after the suggestion title - woocommerce products - image list layout
add_filter('advq_suggestion_title','advq_custom_after_suggestion_title' , 1);
function advq_custom_after_suggestion_title( $title ){
global $post;
$currency = get_woocommerce_currency_symbol();
$realprice = get_post_meta( $post->ID, '_regular_price', true);
return $title. '<div>From ' . $currency . $realprice . '</div>';
}