Skip to content

Instantly share code, notes, and snippets.

View Bobz-zg's full-sized avatar
👨‍💻
working remotely

Vlado Bosnjak Bobz-zg

👨‍💻
working remotely
View GitHub Profile
@Bobz-zg
Bobz-zg / include-pp-woo-products.php
Last active February 27, 2017 16:16
Include password protected products in WooCommerce search results for non-logged in users
<?php
/**
* Place this part of code somewhere in functions.php
*/
add_filter( 'posts_where' , function($q) {
global $wpdb;
$r = "AND ({$wpdb->posts}.post_password = '')";
$q = str_replace($r, '', $q);
@Bobz-zg
Bobz-zg / wistia-video-click-to-play.js
Created January 20, 2017 04:15
Click to play Wistia Video via Javascript API
$('.play').click( function(event) {
if(event.preventDefault) { event.preventDefault(); }
$video = $(this).closest('iframe');
if ( $video.hasClass('wistia_embed') ) {
window._wq = window._wq || [];
$video_id = /[^/]*$/.exec( $video.attr('src') )[0];
@Bobz-zg
Bobz-zg / add-wistia-oembed-support.php
Created January 20, 2017 03:53
Adds support for oEmbed Wistia videos to WordPress
add_action( 'init', function () {
wp_oembed_add_provider( '/https?:\/\/(.+)?(wistia\.com|wi\.st)\/(medias|embed)\/.*/', 'http://fast.wistia.net/oembed', true );
});
@Bobz-zg
Bobz-zg / woo-checkout.php
Last active April 12, 2023 01:41
Pre-populate Woocommerce checkout fields
<?php
/**
* Pre-populate Woocommerce checkout fields
* Note that this filter populates shipping_ and billing_ fields with a different meta field eg 'first_name'
*/
add_filter('woocommerce_checkout_get_value', function($input, $key ) {
global $current_user;
switch ($key) :
@Bobz-zg
Bobz-zg / toggle.html
Created September 9, 2016 16:28
Simple reusable toggle with jquery
<a href="#toggleMe" data-toggle="toggleMe">Toggle div</a>
<div id="toggleMe" class="toggler">
Content goes here ...
</div>
@Bobz-zg
Bobz-zg / toggler.css
Created September 9, 2016 16:00
Simple jquery toggle function Raw
.toggler {
overflow: hidden;
max-height: 0;
transition: max-height .3s ease-in;
}
.toggler.active {
max-height: 2000px;
transition: max-height .3s ease-out;
}
@Bobz-zg
Bobz-zg / toggler.jquery.js
Last active September 9, 2016 16:37
Simple jquery toggle function
$.fn.toggler = function() {
return this.each( function() {
$(this).click(function(event) {
// Prevent click event on a tag
if ($(this).is('a')) {
if(event.preventDefault) { event.preventDefault(); }
}
(function($) {
function triggerError($err, $status) {
$msg = false;
$errors = {
'e100' : "Something went wrong, please try again later",
'e101' : "Please enter you'r username and password",
'e102' : "Please enter you'r email",
'e103' : "Please populate all fields marked with *",
@Bobz-zg
Bobz-zg / filter-posts-mt-terms.php
Last active October 12, 2016 14:16
Filter WordPress posts by multiple taxonomy terms with AJAX and pagination
<?php
/**
* Check if term exists
*/
if (!is_array($terms)) :
$response = [
'status' => 501,
'message' => 'Term doesn\'t exist',
'content' => 0
];
@Bobz-zg
Bobz-zg / filter-posts-mt.php
Last active November 14, 2016 08:11
Filter WordPress posts by multiple taxonomy terms with AJAX and pagination
<?php
function vb_filter_posts_mt() {
if( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'bobz' ) )
die('Permission denied');
/**
* Default response
*/
$response = [