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 / gravity-form-merge-tag-cpt-get-embedded-post-cat.php
Created June 1, 2016 03:29
Gravity Form Merge tag for getting embedded post's category (of custom post type)
<?php
// merge tag for Job Application Category
add_action( 'gform_admin_pre_render', 'sls_add_merge_tags' );
function sls_add_merge_tags( $form ) {
?>
<script type="text/javascript">
gform.addFilter('gform_merge_tags', 'add_merge_tags');
function add_merge_tags(mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option){
mergeTags["custom"].tags.push({ tag: '{embededPostCat}', label: 'Embeded Post Category' });
@ben-heath
ben-heath / custom-woocommerce-shop-loop-thumbnail-and-title.php
Last active September 21, 2021 03:41
Custom WooCommerce Shop Loop Product Thumbnail and Title
<?php
/**
* Check if WooCommerce is active
**/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// remove product thumbnail and title from the shop loop
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
@ben-heath
ben-heath / run-when-in-view.js
Created August 1, 2016 15:59
Run code when a specific html element is visible on a page
var $findit = jQuery('#visualisation'); // element that needs to be in view for thing to happen
function Scrolledit() {
$findit.each(function() {
var $section = jQuery(this),
finditOffset = $section.offset(),
finditTop = finditOffset.top,
finditBottom = $section.height() + finditTop,
scrollTop = jQuery(document).scrollTop(),
visibleBottom = window.innerHeight,
@ben-heath
ben-heath / woocommerce-custom-product-tab-and-meta-field-content.php
Last active July 22, 2022 04:10
Create WooCommerce Product Tab with content from Product Meta custom field
<?php
// add this code to the functions.php file of your Theme or Child Theme
/*
* Add Custom tabs to WooCommerce products which contain content stored in custom fields (product postmeta fields)
* This example is adding 3 tabs. Product Instructions, Size Chart, and Tech Specs
* There are 2 pieces that are needed:
* 1. Declare the tab
* 2. Declare the contents of the tab
* Recommended to use ACF (advanced custom fields plugin) to managage the tab content per product.
@ben-heath
ben-heath / custom-woocommerce-shop-loop-and-single-product-thumbnail-and-title.php
Created September 7, 2016 20:06
Respondo Pro Removal of /woocommerce/single-product/product-image.php file and content-product.php file
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
add_action( 'woocommerce_before_shop_loop_item_title', 'sls_woocommerce_template_loop_product_thumbnail', 10 );
function sls_woocommerce_template_loop_product_thumbnail() {
echo '<a class="thumbnail" title="'.get_the_title().'" href="'. get_the_permalink() . '">'.woocommerce_get_product_thumbnail().'</a>';
echo '<h3><a href="'.get_the_permalink().'">'.get_the_title().'</a></h3>';
}
@ben-heath
ben-heath / acf-featured-image-workaround.php
Created November 2, 2016 18:24
Save value of ACF form field to the featured image of the post.
@ben-heath
ben-heath / display-posts-by-author-subscription-level.php
Created December 13, 2016 03:29
Restricting Display Posts shortcode posts to only show posts by Authors with specific WooCommerce Subscription
<?php
// This is dependant on Display Posts Shortcode plugin - https://wordpress.org/plugins/display-posts-shortcode/
// Alst dependant on WooCommerce Subscriptions Plugin - https://woocommerce.com/products/woocommerce-subscriptions/
// Adding the Author Subscription Level filter to Display Posts shortcode
function be_display_posts_shortcode_exclude_posts( $args, $atts ) {
if( isset( $atts['platinum'] ) ) {
$blogusers = get_users(); // get all users
$platinumUsers = array();
@ben-heath
ben-heath / add-to-woocommerce-additional-info-tab-single-product.php
Last active October 13, 2022 16:22
Add content to WooCommerce Additional Information Tab on Single Products
<?php
// This code should be added to the functions.php file of the child theme
// Add custom info to Additional Information product tab
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
global $product;
$tabs['additional_information']['callback'] = 'custom_function_name'; // this is the function name which is included below
return $tabs;
}
@ben-heath
ben-heath / woocommerce-thankyou-sharesale.php
Created April 19, 2017 15:06
WooCommerce Thank you page - Sharesale tracking image
// This code goes in the functions.php file of you're WP theme (child theme)
add_action('woocommerce_thankyou','sls_sharesale_tracking'); // hook for the thank you page
function sls_sharesale_tracking( $order_id ) { // pass in the order id
$order = new WC_Order( $order_id );
$currency = $order->get_order_currency();
$total = $order->get_total();
$date = $order->order_date;
@ben-heath
ben-heath / respondo-bootstrap-modal-shortcode.php
Created May 2, 2017 13:42
Example Respondo Bootstrap modal shortcode
<?php
/* Bootstrap Docs:
* http://getbootstrap.com/javascript/#modals
* Lots of options could be added as attributes in the shortcode. The attached code is just the pieces I needed at the time.
* This is the simple shortcode:
* [sls-modal id="modal-1" header_text="HEADER TITLE HERE"]
* CONTENT HERE
* [/sls-modal]
* One thing that should be changed, is to allow for other respondo shortcode to be used within the content part.
* I hadn't shorted that out yet.