Skip to content

Instantly share code, notes, and snippets.

Michael Bourne michaelbourne

View GitHub Profile
@michaelbourne
michaelbourne / functions.php
Last active Feb 6, 2019
Swap out iLightBox for newest release (untested)
View functions.php
<?php
add_action( 'wp_enqueue_scripts', 'miro_load_script', 99 );
function miro_load_script() {
wp_deregister_script( 'vendor-ilightbox' );
wp_register_script( 'vendor-ilightbox', get_stylesheet_directory_uri() . '/new-ilightbox.js', array( 'jquery' ), '2.2.4', true );
}
@michaelbourne
michaelbourne / cart-count-shortcode.php
Created Aug 24, 2018
Create a simple shortcode to output the Woocommerce cart count
View cart-count-shortcode.php
<?php
// Add cart count shortcode [cart_count]
// =============================================================================
add_shortcode( 'cart_count', 'mb_cart_count' );
function mb_cart_count(){
if( ! WC()->cart->is_empty() ) {
return WC()->cart->get_cart_contents_count();
}
@michaelbourne
michaelbourne / woocommerce-body-class-cart-items.php
Created Aug 24, 2018
Add a body class when there are items in the Woocommerce cart
View woocommerce-body-class-cart-items.php
<?php
// Add a body class via the body_class filter in WP
// =============================================================================
add_filter( 'body_class', 'mb_body_class_for_cart_items' );
function mb_body_class_for_cart_items( $classes ) {
if( ! WC()->cart->is_empty() ){
$classes[] = 'cart-has-items';
}
return $classes;
@michaelbourne
michaelbourne / pro-cart-count.php
Last active Feb 25, 2019
Add a simple cart count to the Pro header builder cart elements
View pro-cart-count.php
<?php
// Add cart count and value to Cart Element text in a Pro header
// =============================================================================
add_filter('woocommerce_add_to_cart_fragments', 'mb_cart_count_fragments', 10, 1);
function mb_cart_count_fragments($fragments) {
$count = WC()->cart->get_cart_contents_count();
$fragments['.cartdropdown .x-anchor-text-primary'] = '<span class="x-anchor-text-primary">' . $count . '</span>';
return $fragments;
}
@michaelbourne
michaelbourne / pro-cart-count-total.php
Last active Aug 24, 2018
Add the Woocommerce cart count and cart total to a cart element in the Pro header builder.
View pro-cart-count-total.php
<?php
// Add cart count and value to Cart Element text in a Pro header
// =============================================================================
add_filter('woocommerce_add_to_cart_fragments', 'mb_cart_count_fragments', 10, 1);
function mb_cart_count_fragments($fragments) {
$count = WC()->cart->get_cart_contents_count();
$value = ($count == 0) ? '$0.00' : WC()->cart->get_cart_total();
$cart = ($count == 0) ? 'Cart' : 'Items: ' . $count;
@michaelbourne
michaelbourne / pro-builder-indicator-with-posts.php
Last active Nov 21, 2018
Adds a custom column to the admin Pages/Posts list indicating if the page was built in Pro. Only use one of these snippets.
View pro-builder-indicator-with-posts.php
<?php
// Add visual indicator to pages and posts built in Pro
// =============================================================================
function bourne_identity_columns( $columns ) {
$myCustomColumns = array(
'probuilder' => __( 'Builder' )
);
$columns = array_merge( $columns, $myCustomColumns );
@michaelbourne
michaelbourne / custom-fonts.js
Last active Feb 25, 2019
Add custom font families to the Pro font manager
View custom-fonts.js
(function(){ var config = cornerstoneApp.lookup('service:store').peekRecord('option','cornerstone_font_config');config.set('value.customItems', [ { family: 'MikesFont', stack: 'MikesFont, sans-serif', weights: [ '300', '500' ]}]);config.save()})();
@michaelbourne
michaelbourne / single-product-ajax-add-to-cart.js
Last active Jun 14, 2018
JS and PHP needed for Single Product template to use AJAX Add To Cart functionality
View single-product-ajax-add-to-cart.js
jQuery(document).ready(function($){
// The X/Pro "Added to cart" overlay
var notification = $('.x-cart-notification');
$(".single_add_to_cart_button").on('click', function(e) {
e.preventDefault();
var quantity = $('input[name="quantity"]').val(),
@michaelbourne
michaelbourne / x-pro-anchor-link-scroll.js
Last active May 28, 2018
Override deafult scroll handling for anchor links, set offset for sticky header.
View x-pro-anchor-link-scroll.js
@michaelbourne
michaelbourne / x-js-grid.js
Created May 2, 2018
X Theme / Pro Theme javascript based grid
View x-js-grid.js
(function($){
$(window).on('ready load resize', function(){
var max = 0,
mobile = $(window).width(),
numChildren = $('.jsmethodgrid').first().children().size();
$(".jsmethodgrid .x-column").css('min-height','inherit');
if ( mobile > 767 ){
$('.jsmethodgrid .x-column').css({ 'width' : 100/numChildren + '%', 'margin': 0 });
You can’t perform that action at this time.