Skip to content

Instantly share code, notes, and snippets.

View jrick1229's full-sized avatar
☠️

Joey Ricketts jrick1229

☠️
  • VA
  • 04:52 (UTC -04:00)
View GitHub Profile
@jrick1229
jrick1229 / eg_extend_subscription_expiration_options.php
Last active November 29, 2018 17:18
Extend the expiration options for subscriptions
<?php
function eg_extend_subscription_expiration_options( $subscription_lengths ) {
$subscription_lengths['year'][10] = wcs_get_subscription_period_strings( 10, 'year' );
$subscription_lengths['year'][20] = wcs_get_subscription_period_strings( 20, 'year' );
$subscription_lengths['month'][48] = wcs_get_subscription_period_strings( 48, 'month' );
return $subscription_lengths;
}
add_filter( 'woocommerce_subscription_lengths', 'eg_extend_subscription_expiration_options' );
@jrick1229
jrick1229 / wcs_change_billing_details_string.php
Last active November 29, 2018 17:17
Change 'Billing Details' title in checkout to be 'Account Info' when cart total is equal to ZERO
<?php
function wcs_free_checkout_fields() {
// Bail we're not at checkout, or if we're at checkout but payment is needed
if ( function_exists( 'is_checkout' ) && ( ! is_checkout() || ( is_checkout() && WC()->cart->needs_payment() ) ) ) {
return;
}
// Change string here
@jrick1229
jrick1229 / renewal_choice_type_cart.php
Last active November 29, 2018 17:17
renewal_choice_type_cart
<?php
function renewal_choice_type_cart() {
?>
<div class="renewal-cart-choice-field">
<label for="renewal-cart-choice">Renewal method:</label>
<select id="renewal-cart-choice" name="renewal-cart-choice">
<option value="auto">Automatic Renewal</option>
<option value="manual">Manual Renewal</option>
</select>
<?php
/**
* Function to redirect the customer to a custom 'thank you' page after placing an order
**/
add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( ' http://localhost:8888/subscriptions/custom-thank-you-page/' );
@jrick1229
jrick1229 / eg_my_custom_retry_rules.php
Last active November 29, 2018 17:16
Immediately 'Cancel' the subscription after the fifth payment retry
<?php
function eg_my_custom_retry_rules( $default_retry_rules_array ) {
return array(
array(
'retry_after_interval' => 3 * DAY_IN_SECONDS,
'email_template_customer' => '',
'email_template_admin' => 'WCS_Email_Payment_Retry',
'status_to_apply_to_order' => 'pending',
'status_to_apply_to_subscription' => 'on-hold',
<?php
add_filter( 'woocommerce_payment_complete_order_status', 'wcs_aco_return_completed' );
/**
* Return "completed" as an order status.
*
* This should be attached to the woocommerce_payment_complete_order_status hook.
*
* @since 1.1.0
*
@jrick1229
jrick1229 / auto_add_to_cart_OPC.php
Last active November 29, 2018 17:16
Auto-add product to cart on page visit
<?php
add_action( 'wp', 'auto_add_to_cart_OPC' );
function auto_add_to_cart_OPC() {
$product_id = 561;
$page_id = 332;
if ( is_page( $page_id ) ) {
WC()->cart->empty_cart();
@jrick1229
jrick1229 / paypal-billing-id-prefixes.md
Created September 19, 2018 15:38
PayPal Billing ID Prefixes
@jrick1229
jrick1229 / custom_one_time_purchase_string.php
Last active November 29, 2018 17:15
Change the 'None' string in SATT
<?php
add_filter( 'wcsatt_single_product_one_time_option_description', 'custom_one_time_purchase_string', 12, 2 );
function custom_one_time_purchase_string( $none_string, $product ) {
// Alter the value of $none_string to use a custom string
$none_string = "One-Time Purchase";
return $none_string;
}
@jrick1229
jrick1229 / add-to-cart.html
Created November 2, 2018 14:25
Add a variation to the cart and go directly to checkout.
<input type="button" onclick="location.href='http://testsubs2.local/checkout/?add-to-cart=56&variation_id=57';" value="Buy Now" />