Skip to content

Instantly share code, notes, and snippets.

View CrispDev's full-sized avatar

Crisp Design Custom Dev CrispDev

  • Crisp Design Co. Custom Project Development
  • Denver, CO
View GitHub Profile
@CrispDev
CrispDev / wc-ajax-autoship-add-to-cart.js
Last active April 20, 2019 19:27
Woocommerce with Autoship Powered by QPilot Ajax Add To Cart Button
jQuery( function($) {
/* ------------------------------------------------------------------------------------ */
/* Document Ready */
/* ------------------------------------------------------------------------------------ */
$(document).ready( function() {
// Attach the Ajax class to the add-to-cart button
$(".single_add_to_cart_button").addClass("ajax_add_to_cart");
@CrispDev
CrispDev / functions.php
Created December 27, 2018 19:52
Woocommerce with Autoship Powered by QPilot Dynamic Checkout Price
<?php
/**
* Applies a custom checkout price to a speicific priduct with a frequency type and number
* otherwise returns original checkout price.
* @param float $checkout_price. The current discounted or not checkout price for this autoship product.
* @param int $product_id. The current product's id.
* @param string $frequency_type. The Autoship frequency type ( Months, Days, etc ).
* @param int $frequency. The frequency value.
*
* @return float The new calculated checkout price or the originally supplied
@CrispDev
CrispDev / functions.php
Created December 27, 2018 20:03
Woocommerce with Autoship Powered by QPilot Dynamic Price HTML
<?php
add_filter('autoship_simple_product_discount_price_html_selector' , 'customize_autoship_simple_product_price_selector', 10, 1 );
function customize_autoship_simple_product_price_selector( $selector ){
return '.entry-summary__inventory > .woocommerce-Price-amount';
}
add_filter('autoship_simple_product_discount_price_html', 'customize_autoship_simple_product_price_html', 10 , 3 );
function customize_autoship_simple_product_price_html( $discounted_price_html, $autoshipCheckoutPrice, $product ){
$autoshipNormalPrice = $product->get_price();
@CrispDev
CrispDev / functions.php
Created January 17, 2019 16:18
Default Autoship Fequency & Frequency Type Options on Product Page
function autoship_new_default_frequency_options( $options ) {
// Return a new set of default frequency options of 1 through 4 Weeks
return array(
array(
// Days, Weeks, Months, DayOfTheWeek, DayOfTheMonth
'frequency_type' => 'Weeks',
// Frequency (integer)
'frequency' => 2,
'display_name' => 'Every 2 Weeks'
),
@CrispDev
CrispDev / functions.php
Created January 21, 2019 17:24
Default Autoship by default instead of one-time purchase
// Default the Autoship option for both Simple and
// Variable products by default.
function xx_default_autoship_for_all( $default ){
return 'yes';
}
add_filter('autoship_default_product_schedule_options_choice_value', 'xx_default_autoship_for_all', 10 ,1);
@CrispDev
CrispDev / functions.php
Created February 4, 2019 01:40
Adjust Checkout and Recurring Price based on Frequency and Type
// Adjust Scheduled Order Checkout Price.
function xx_adjust_checkout_price( $checkout_price, $product_id, $frequency_type, $frequency ){
// Adjust the checkout price based on the frequency and type
if ( ( 'Days' == $frequency_type ) && ( 1 == $frequency ) ){
$discount_pct = .5;
} else if ( ( 'Weeks' == $frequency_type ) && ( 1 == $frequency ) ){
@CrispDev
CrispDev / product-options.js
Created February 4, 2019 15:32
Display a custom discounted price based on Selected Autoship frequency & type ( Simple Product Type Example )
jQuery(function ($) {
/**
* Displays a custom discounted price based on
* Selected Autoship frequency & type.
*/
function xx_custom_autoship_schedule_options_price($) {
// Add the discount data per frequency and type as a variable loaded into the page.
var option_price_discount_lookup = {
@CrispDev
CrispDev / functions.php
Last active February 11, 2019 14:27
Autoship Customization // Require N Number of Autoship Products for Valid Coupon
function increase_required_cart_qty( $count ){
return $count >= 3;
}
function autoship_adjust_coupon_is_valid( $valid, $coupon ) {
add_filter( 'autoship_valid_cart_total_min_required','increase_required_cart_qty', 10, 1);
$valid = autoship_cart_has_valid_autoship_items();
remove_filter( 'autoship_valid_cart_total_min_required','increase_required_cart_qty');
return $valid;
@CrispDev
CrispDev / functions.php
Last active May 15, 2019 18:58
Autoship Customization // Customize Order Status Nicenames
/**
* Filter the Status names displayed in the Native Scheduled Order dashboard and order detail page.
* @param array $statuses The current status and it's display name.
* @return array
*/
function xx_adjust_autoship_status_nicenames( $statuses ){
// Optionally use autoship_rights_checker() to determine which version of nicenames to display
return array (
'Active' => 'Scheduled',
@CrispDev
CrispDev / functions.php
Created February 11, 2019 15:18
Autoship Customization // Add Filter to Default Updating a Users existing Autoship Orders with new Address Info.
/**
* Force all the users autoship orders to be updated if the user
* Changes their address info.
*
* @param bool $update The current update flag. True updates all orders, false doesn't
* @param int $user_id The current users id.
*
* @return bool The filtered update flag.
*/