Skip to content

Instantly share code, notes, and snippets.

View lucasstark's full-sized avatar

Lucas Stark lucasstark

View GitHub Profile
@lucasstark
lucasstark / gist:4370071
Created December 24, 2012 17:17
Swatches 1.1.2 updated JS file.
jQuery(document).ready( function($) {
var calculator = new variation_calculator(product_attributes, product_variations_flat, my_all_set_callback, my_not_all_set_callback);
calculator.reset_selected();
calculator.reset_current();
function my_not_all_set_callback() {
// Reset image
var img = $('div.images img:eq(0)');
var link = $('div.images a.zoom:eq(0)');
@lucasstark
lucasstark / gist:4698439
Created February 2, 2013 17:31
sample trial download shortcode
add_shortcode('trial_contents', 'do_trial_contents');
function do_trial_contents($atts='') {
$content = '';
if (trial_check_cookie()) {
$content = trial_get_the_download_link();
} else {
if (!empty($_POST) && isset($_POST['action']) && $_POST['action'] == 'trial-signup'){
global $post;
if (basename( get_page_template() ) != 'some-template.php') {
$featured_image_post = get_featured_recursive($post);
if ($featured_image_post != null) {
$featured_image_src = wp_get_attachment_image_src(get_post_thumbnail_id($featured_image_post), 'single-post-thumbnail'); ?>
<img src="<?php echo $featured_image_src[0]; ?>" alt="<?php the_title(); ?>" />
<?php }
else {
if (has_post_thumbnail()){
//output the thumbnail normally
@lucasstark
lucasstark / gist:5600480
Last active December 17, 2015 11:09
// Minimal YouTube & Vimeo embeds
// Minimal YouTube & Vimeo embeds
function theme_oembed_get($url, $args = '') {
if (preg_match("/youtube.com\/watch\?v=([^&]+)/i", $url, $aMatch)) {
return '<iframe width="' . $args['width'] . '" height="' . $args['height'] . '" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>';
}
if (preg_match("/youtube.com\/watch\?feature=player_embedded&v=([^&]+)/i", $url, $aMatch)) {
return '<iframe width="' . $args['width'] . '" height="' . $args['height'] . '" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>';
}
@lucasstark
lucasstark / gist:5612750
Created May 20, 2013 14:55
WooCommerce Dynamic Pricing - Display the discounts available for a particular product category.
add_action('woocommerce_single_product_summary', 'my_after_woocommerce_single_product_summary', 21);
function my_after_woocommerce_single_product_summary() {
global $post, $product;
if (is_object_in_term($post->ID, 'product_cat', array('tshirts'))) {
echo 'Your Custom Pricing Table';
}
}
@lucasstark
lucasstark / gist:6071982
Created July 24, 2013 16:05
Example of the problem
$nav = array(
array(
'item1',
'item2',
'item3'
),
array(
'item1',
'item2',
'item3'
@lucasstark
lucasstark / catalog-visibility-options-filters
Created August 21, 2013 12:22
Use filters to control who can view and purchase products when using WooCommerce Catalog Visibility Options.
function set_catalog_visibility_user_can_purchase($result, $product){
$result = false; //set the default.
//create an array of roles and their assoicated categories.
$allowed = array(
'customer' => array(
'bakeware',
'appliances',
'category-1',
),
<?php
/*-----------------------------------------------------------------------------------*/
/* Custom Softwright Upcoming Events /*
/*-----------------------------------------------------------------------------------*/
if( ! class_exists( 'sw_upc_events_widget' ) ) :
class sw_upc_events_widget extends WP_Widget {
function sw_upc_events_widget() {
$widget_ops = array( 'description' => __( 'Displays closest Upcoming Events by date' ), 'classname' => 'upcoming-event-widget' );
$this->WP_Widget( 'upc_event_widget', __( 'Softwright Upcoming Events' ), $widget_ops );
@lucasstark
lucasstark / gist:6594983
Created September 17, 2013 14:21
Example to add meta data to woocommerce cart items
<?php
/*
* Plugin Name: Example Modify Price
*/
class Example_Modify_Price {
private static $instance;
public static function register() {
if (self::$instance == null) {
$amount = apply_filters('woocommerce_dynamic_pricing_get_rule_amount', $rule['amount'], $rule, $cart_item, $this);
switch ($rule['type']) {
case 'price_discount':
$adjusted = floatval($price) - floatval($amount);
$result = $adjusted >= 0 ? $adjusted : 0;
break;
case 'percentage_discount':
if ($amount > 1) {
$rule['amount'] = $amount / 100;