Skip to content

Instantly share code, notes, and snippets.

View dancameron's full-sized avatar
💭
🍻Cheersing

Dan Cameron dancameron

💭
🍻Cheersing
View GitHub Profile
@dancameron
dancameron / gist:5413998
Created April 18, 2013 16:12
MP Process

get_mp_link()

Using a create_preference() function within MP class.

Response

[18-Apr-2013 15:39:33] create preference response: Array
(
   [status] => 201

[response] => Array

<?php
/*
Usage:
$frag = new CWS_Fragment_Cache( 'unique-key', 3600 ); // Second param is TTL
if ( !$frag->output() ) { // NOTE, testing for a return of false
functions_that_do_stuff_live();
these_should_echo();
// IMPORTANT
$frag->store();
// YOU CANNOT FORGET THIS. If you do, the site will break.
@dancameron
dancameron / gist:5569708
Last active December 17, 2015 06:59
Edit review controls.
<?php
remove_all_filters( 'group_buying_template_checkout/review-controls.php' );
add_filter( 'group_buying_template_checkout/review-controls.php', 'new_paypal_controls' );
function new_paypal_controls() {
echo '<div class="checkout-controls">
<input type="hidden" name="" value="'.Group_Buying_Offsite_Processors::CHECKOUT_ACTION.'">
<input class="form-submit submit checkout_next_step" type="submit" value="'.gb__( 'NEW!' ).'" name="gb_checkout_button" />
</div>';
}
@dancameron
dancameron / filters.php
Created September 18, 2013 21:48
redirect non logged in users away from checkout
add_action( 'template_redirect', 'redirect_away_from_checkout' );
function redirect_away_from_checkout() {
if ( !is_user_logged_in() && gb_on_checkout_page() ) {
wp_redirect( add_query_arg( array( 'redirect_to' => gb_get_checkout_url() ), gb_get_account_login_url() ) );
exit();
}
}
@dancameron
dancameron / chartjs_responsive_ajax_example.html
Last active May 8, 2018 14:10
Responsive Chart.js Example with AJAX Callback
<canvas id="invoice_status_chart" min-height="300" max-height="500"></canvas>
<script type="text/javascript" charset="utf-8">
var invoice_status_data = {};
function invoice_status_chart() {
var can = jQuery('#invoice_status_chart');
var ctx = can.get(0).getContext("2d");
var container = can.parent().parent(); // get width from proper parent
@dancameron
dancameron / demo-shortcode.php
Last active August 29, 2015 14:04
Shortcode to retrieve remote form - ninjademo.com
<?php
/**
* Add the remote form via AJAX or php get.
* Shortcode is [sa-create-demo-form]
* Currently no attributes are used even though they could be used
* so that the $demo_url variable doesn't need to be updated manually below.
*
* @param array $atts shortcode atts
* @return string Create demo form.
*/
<?php
/*
Plugin Name: NinjaDemo AJAX Callbacks
Plugin URI: https://sproutapps.co/
Description: Allow for the demo form to be remotely retreived.
Author: Sprout Apps
Version: 0.8
Author URI: https://sproutapps.co
*/
@dancameron
dancameron / functions.php
Last active October 16, 2015 21:31
Filter Default Estimation Fields
<?php
function filter_si_submission_form_fields( $fields = array() ) {
// Remove the budget field
unset( $fields['budget'] );
$fields['examples'] = array(
'weight' => 120,
'label' => __( 'Examples' ),
'type' => 'textarea',
'required' => TRUE,
@dancameron
dancameron / functions.php
Last active September 24, 2015 15:27
Customizing Sprout Invoice Templates (via CSS)
<?php
/**
* Hook into si_head hook and add a new custom CSS stylesheet.
*
*/
function si_add_stylesheet() {
echo '<link rel="stylesheet" id="sprout_doc_style-css" href="'.get_stylesheet_directory_uri() . '/css/sprout-invoices.custom-style.css" type="text/css" media="all">';
}
add_action( 'si_head', 'si_add_stylesheet' );
@dancameron
dancameron / functions.php
Created August 18, 2014 03:39
Fix for Recurring EDD Payments with Discounts (Paypal).
<?php
// filter paypal because of discount
function sa_mod_paypal_gateway_data( $paypal_args = array(), $purchase_data = array() ) {
if ( isset( $paypal_args['cmd'] ) && $paypal_args['cmd'] == '_xclick-subscriptions' ) {
$paypal_args['sra'] = '3'; // change failed attempts.
if ( $paypal_args['a3'] < 0.00 && isset( $purchase_data['discount'] ) ) {
// Fix recurring amount
$paypal_args['a3'] += $purchase_data['discount'];
// fix single item, it matches the recurring amount.