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 / 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-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 / 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.
*/
@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 / 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 / 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 / simple-modal-popup.css
Created March 26, 2020 18:44
Simple JavaScript Popup Modal
/* Put this in your preferred CSS location */
/* Modal CSS */
/* The Modal (background) */
.sls-modal {
display: none;
position: fixed;
z-index: 999;
left: 0;
right: 0;
top: 0;
@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 / 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 / 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;