Skip to content

Instantly share code, notes, and snippets.

View jrick1229's full-sized avatar
☠️

Joey Ricketts jrick1229

☠️
  • VA
  • 11:00 (UTC -04:00)
View GitHub Profile
@jrick1229
jrick1229 / standalone-add-to-cart-button.html
Created June 25, 2018 18:57
Add an add-to-cart button anywhere
<input type="button" onclick="location.href='http://your-site.com/cart/?add-to-cart=[product-ID]';" value="Buy Now" />
@jrick1229
jrick1229 / paypal-billing-id-prefixes.md
Created September 19, 2018 15:38
PayPal Billing ID Prefixes
@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" />
@jrick1229
jrick1229 / wcs_my_custom_retry_rules.php
Last active November 29, 2018 16:50
Email customer immediately upon first failed payment
<?php
function wcs_my_custom_retry_rules( $default_retry_rules_array ) {
return array(
array(
'retry_after_interval' => DAY_IN_SECONDS / 2, // how long to wait before retrying
'email_template_customer' => 'WCS_Email_Customer_Payment_Retry', // email customer immediately upon first failed payment
'email_template_admin' => 'WCS_Email_Payment_Retry',
'status_to_apply_to_order' => 'pending',
'status_to_apply_to_subscription' => 'on-hold',
@jrick1229
jrick1229 / disable_user_role_change.php
Last active November 29, 2018 16:51
WCS - Don't change user role when subscribing
<?php
add_filter( 'woocommerce_subscriptions_update_users_role', '__return_false', 100 );
@jrick1229
jrick1229 / wcs_redirect_to_cart.php
Last active November 29, 2018 16:51
Redirect customer to cart page when 'Mixed Checkout' is enabled and product is added to cart
<?php
function wcs_redirect_to_cart( $url ) {
// If product is of the subscription type
if ( is_numeric( $_REQUEST['add-to-cart'] ) && WC_Subscriptions_Product::is_subscription( (int) $_REQUEST['add-to-cart'] ) ) {
// Redirect to cart instead
$url = WC()->cart->get_cart_url();
}
return $url;
}
@jrick1229
jrick1229 / hide_cancel_button.php
Last active November 29, 2018 16:52
Hide the 'Cancel' button from the My Account page with Subscriptions
<?php
function eg_remove_my_subscriptions_button( $actions, $subscription ) {
foreach ( $actions as $action_key => $action ) {
switch ( $action_key ) {
case 'cancel': // Hide "Cancel" button on subscriptions that are "active" or "on-hold"?
unset( $actions[ $action_key ] );
break;
default:
error_log( '-- $action = ' . print_r( $action, true ) );
@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 / 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();
<?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
*