Skip to content

Instantly share code, notes, and snippets.

View michaelbourne's full-sized avatar

Michael Bourne michaelbourne

View GitHub Profile
@michaelbourne
michaelbourne / x-pro-anchor-link-scroll.js
Last active May 28, 2018 21:52
Override deafult scroll handling for anchor links, set offset for sticky header.
@michaelbourne
michaelbourne / single-product-ajax-add-to-cart.js
Last active June 14, 2018 18:02
JS and PHP needed for Single Product template to use AJAX Add To Cart functionality
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 / recent-posts-excerpt.php
Last active August 23, 2018 19:33
Add Excerpt to Recent Posts Shortcode
// Displaying Excerpt in Recent Posts
// =============================================================================
function x_shortcode_recent_posts_v2( $atts ) {
extract( shortcode_atts( array(
'id' => '',
'class' => '',
'style' => '',
'type' => 'post',
'count' => '',
@michaelbourne
michaelbourne / pro-cart-count-total.php
Last active August 24, 2018 21:55
Add the Woocommerce cart count and cart total to a cart element in the Pro header builder.
<?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 November 21, 2018 20:12
Adds a custom column to the admin Pages/Posts list indicating if the page was built in Pro. Only use one of these snippets.
<?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 / functions.php
Last active February 6, 2019 22:58
Swap out iLightBox for newest release (untested)
<?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 / pro-cart-count.php
Last active February 25, 2019 22:58
Add a simple cart count to the Pro header builder cart elements
<?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 / custom-fonts.js
Last active February 25, 2019 23:07
Add custom font families to the Pro font manager
(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 / pro-colors-anywhere.php
Last active February 25, 2019 23:19
How to use Themeco Pro template colors anywhere on your site
/**
* Get theme colors from Pro and turn them into classes and CSS variables
* Author: Michael Bourne
*/
$themecolors = get_option('cornerstone_color_items');
if($themecolors) {
$css = '<style type="text/css" id="themecolours">';
$colors = json_decode( stripslashes( $themecolors ), true );
@michaelbourne
michaelbourne / override-header-assignment-4.php
Last active March 19, 2019 23:42
Override the Pro Theme header assignment for specific pages and conditions
add_filter('cs_match_header_assignment', 'custom_search_header');
function custom_search_header($match) {
$user = wp_get_current_user();
if (in_array( 'author', (array) $user->roles )) {
$match = 1234; // the post ID for your header
}
return $match;
}