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 / woo-template-parts-filter.php
Created October 12, 2018 09:30
Quickly unhook WooCommerce template parts
<?php
/**
* Remove variouse template parts in WooCommerce
*/
add_filter( 'wc_get_template', function( $located, $template_name, $args, $template_path, $default_path ) {
$remove = [
'sale-flash.php',
'meta.php',
@Bobz-zg
Bobz-zg / redirect-wp-post.php
Last active April 12, 2023 09:37
Redirects wordpress posts to new url: site.com/blog/post-name
<?php
/**
* Add new rewrite rule
*/
function create_new_url_querystring() {
add_rewrite_rule(
'blog/([^/]*)$',
'index.php?name=$matches[1]',
'top'
);
@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 / functions.php
Last active January 17, 2023 20:30
Filter WordPress posts by custom taxonomy term with AJAX
<?php
/**
* AJAC filter posts by taxonomy term
*/
function vb_filter_posts() {
if( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'bobz' ) )
die('Permission denied');
/**
@Bobz-zg
Bobz-zg / debug-wpmail.php
Last active November 13, 2022 15:02
Debug wp_mail function. Display errors on screen
<?php
/**
* Display errors
*/
if ( ! function_exists('debug_wpmail') ) :
function debug_wpmail( $result = false ) {
if ( $result )
return;
@Bobz-zg
Bobz-zg / wc-coupon-loggedin-only.php
Last active November 8, 2022 14:24
Set woocommerce coupon to be available only for logged in users
<?php
add_filter( 'woocommerce_coupon_is_valid', function( $is_valid, $coupon ) {
/**
* Selected coupons allowed for logged in users only
*/
if ( in_array( $coupon->get_code() , ['loggedinonly', 'anothercoupontitle']) && ! is_user_logged_in() )
{
return false;
@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 / filter-posts-mt.js
Last active September 8, 2022 08:22
Filter WordPress posts by multiple custom taxonomy terms with AJAX
(function($) {
$doc = $(document);
$doc.ready( function() {
/**
* Retrieve posts
*/
function get_posts($params) {
@Bobz-zg
Bobz-zg / shortcode.php
Last active September 7, 2022 11:17
Filter WordPress posts by custom taxonomy term with AJAX
<?php
/**
* Shortocde for displaying terms filter and results on page
*/
function vb_filter_posts_sc($atts) {
$a = shortcode_atts( array(
'tax' => 'post_tag', // Taxonomy
'terms' => false, // Get specific taxonomy terms only
'active' => false, // Set active term by ID
@Bobz-zg
Bobz-zg / lightning-address.php
Last active June 6, 2022 06:49
Add Lightning address to WordPress head
<?php
/**
* Plugin Name: Lightning Address
* Plugin URI: https://gist.github.com/Bobz-zg/5e8fe19442d88ddb32bae428dfc199f3/edit
* Author: Vlado Bosnjak
* Author URI: https://github.com/code-soup
* Description: Handle the basics with this plugin.
* Version: 0.0.1
* Requires at least: 5.2