Skip to content

Instantly share code, notes, and snippets.

View ben-heath's full-sized avatar

ben-heath

View GitHub Profile
@ben-heath
ben-heath / hide-woocommerce-product-price-add-to-cart-button.php
Created June 22, 2017 14:35
Hide WooCommerce Product Price and Add to Cart button of Specific products
// Add this to the child theme's functions.php
// This will hide the Price of the product, and swap it out with text of your choice. It will also remove the add to cart button.
// It could probably be more elegant, since some of the code is duplicated between the 2 functions, but it works just fine as is.
// Remove add to cart functionality for specific products
add_filter('woocommerce_is_purchasable', 'my_woocommerce_is_purchasable', 10, 2);
function my_woocommerce_is_purchasable($is_purchasable, $product) {
$skus = array('40-50-134','40-50-132','RB1000','RB1008','RB1009','RP1000','90-15-008','RP1009','RB1010','RB1011','RB1014','RB1016','RP1034','RP1036','40-50-125','RB1013','DB5018','DB5016','DB5006','XR5048','RG1000','DB5025','40-50-115','40-50-114','40-50-117','40-50-110','40-50-136','40-50-121','40-50-108','40-50-113','40-50-111','40-50-105','40-50-106');
$id = array();
@ben-heath
ben-heath / link-and-scroll-to-tab.js
Created September 5, 2017 16:44
Link to specific tab on different page (or same page)
@ben-heath
ben-heath / animated-counter-intersectionObserver.js
Created February 23, 2018 23:21
Makes numbers animate from a number to another number (using IntersectionObserver API)
jQuery(document).ready(function(){
//jQuery('#rs-fullwidth-helper1').before('<p style="color:black;">testing4</p>');
function countUp() {
jQuery('.counter').each(function() {
var counter = jQuery(this),
countTo = counter.attr("data-count");
jQuery({ countNum: counter.text()}).animate({
countNum: countTo
@ben-heath
ben-heath / breadcrumb-shortcode.php
Created March 14, 2018 20:17
Short to add breadcrumb
function breadcrumbs() {
global $post;
ob_start();
// Code
if(!is_home()) {
$breadcrumb = '<nav class="breadcrumb">';
$breadcrumb .= '<a href="'.home_url('/').'">Home</a><span class="divider"> / </span>';
if (is_category() || is_single()) {
$breadcrumb .= the_category(' <span class="divider"> / </span> ');
if (is_single()) {
@ben-heath
ben-heath / bootstrap-2-modal.php
Created March 16, 2018 14:36
This code works with bootstrap 2, and fixes the show/hide behavior experienced with Respondo if following normal Bootstrap documentation
# Trigger button/link
# Must use the 'onClick' method to target the modal, rather than 'data-target'
<a href="javascript:void(0);" id="login-pop-trigger" onClick="jQuery(\'#login-popup\').modal();" role="button" data-toggle="modal"><i class="fas fa-user-plus" aria-hidden="true"></i> Login</a>
# Simple Modal
<div id="login-popup" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-body">
<p>You are about to delete this Page, this is irreversible.</p>
</div>
</div>
@ben-heath
ben-heath / shortcode-list-cpt-posts.php
Created April 11, 2018 15:25
Shortcode list CPT posts
<?php
add_shortcode( 'video-testimonials', 'sls_video_testimonial_short_code' );
function sls_video_testimonial_short_code( $atts ) {
ob_start();
$query = new WP_Query( array(
'post_type' => 'video-testimonial',
'posts_per_page' => 4,
'order' => 'ASC',
'orderby' => 'title',
@ben-heath
ben-heath / reorder-html-by-data-attribute.php
Created April 11, 2018 21:51
Reorder html elements by data attribute using JS
<script>
/*
* This simple script will take multiple html elements, like a group of <li> or <span> or anything,
* and reorder them by the data attribute.
* Example:
* The script will reorder this:
* <span data-test="1">Number 1</span>
* <span data-test="4">Number 2</span>
* <span data-test="3">Number 3</span>
* <span data-test="2">Number 4</span>
@ben-heath
ben-heath / sls-countdown-flipper-clock.php
Created August 31, 2018 14:15
WordPress Shortcode countdown clock using FlipClock.js
<?php
/* Need to include flipclock.js's css and js files. Instructions found on their github page
* http://flipclockjs.com
*
*/
// Flipper countdown function
function sls_flipper_countdown($atts){
// Attributes - For the End Date
extract( shortcode_atts(
array(
@ben-heath
ben-heath / custom-child-theme-customizer.php
Created February 8, 2019 20:46
Add custom customizer sections / panels for Wordpress child theme
<?php
function fod_custom_customizer_options( $wp_customize ) {
$wp_customize->add_section( 'fod_options' , array(
'title' => __('Homepage Popup Form'),
'panel' => '',
'priority' => 1000
) );
@ben-heath
ben-heath / facetwp-template-display-if-facet-selected.php
Last active June 9, 2022 19:07
FacetWP - show template only if a facet is selected
<?php
/* This code goes into your child theme's function.php file
* Or it can use FacetWP's recommendation and use a plugin https://facetwp.com/how-to-use-hooks/
*
* I found that the tutorial on FacetWP's site didn't function how I wanted it to.
* https://facetwp.com/how-to-hide-the-template-until-facets-are-selected/
* Their method doesn't allow a template to show if you use a link with a url query, indicating a facet selection, it only works if
* if you 'click' on the page. So I came up with some JS that looks at the facet list, and looks for any 'checked' items.
* This way, whether it was clicked while on the page, or you linked to the page with a query string selection, it still works as I wanted.
*/