Skip to content

Instantly share code, notes, and snippets.

View woogist's full-sized avatar

WooCommerce.com Documentation woogist

View GitHub Profile
function wc_subscriptions_custom_price_string( $pricestring ) {
global $product;
$products_to_change = array( 45, 90, 238 );
if ( in_array( $product->id, $products_to_change ) ) {
$pricestring = str_replace( 'every 3 months', 'per season', $pricestring );
}
return $pricestring;
function wc_subscriptions_custom_price_string( $pricestring ) {
$newprice = str_replace( 'every 3 months', 'per season', $pricestring );
return $newprice;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'wc_subscriptions_custom_price_string' );
add_filter( 'woocommerce_subscription_price_string', 'wc_subscriptions_custom_price_string' );
add_action( 'wp', 'custom_hidden_comments' );
function custom_hidden_comments() {
$restrictions = wc_memberships()->restrictions;
remove_filter( 'wp', array( $restrictions, 'hide_restricted_content_comments' ) );
}
add_filter( 'wp', 'custom_hide_restricted_content_comments' );
function custom_hide_restricted_content_comments( $content ) {
if ( is_singular() ) {
@woogist
woogist / functions.php
Created July 31, 2015 12:14
Change the "Add to Cart" text on the single product page based on the product ID
/**
* Change the "Add to Cart" text on the single product page based on the product ID
*
* @param string $text
* @param object $product
* @return string
*/
function wc_custom_single_addtocart_text( $text, $product ) {
$products = array( 1, 2, 3 );
add_filter( 'wc_session_expiring', create_function( '', 'return "2 * 60";' ) );
add_filter( 'wc_session_expiration', create_function( '', 'return "3 * 60";' ) );
.wc-bookings-date-picker .ui-datepicker td.ui-datepicker-current-day + td a,
.wc-bookings-date-picker .ui-datepicker td.ui-datepicker-current-day + td + td a,
.wc-bookings-date-picker .ui-datepicker td.ui-datepicker-current-day + td + td + td a,
.wc-bookings-date-picker .ui-datepicker td.ui-datepicker-current-day + td + td + td + td a,
.wc-bookings-date-picker .ui-datepicker td.ui-datepicker-current-day + td + td + td + td + td a,
.wc-bookings-date-picker .ui-datepicker td.ui-datepicker-current-day + td + td + td + td + td + td a {
background-color: #239e57 !important;
}
function eg_do_not_activate_subscription_on_processing(){
remove_action( 'woocommerce_order_status_processing', 'WC_Subscriptions_Manager::activate_subscriptions_for_order' );
remove_action( 'woocommerce_order_status_processing', 'WC_Subscriptions_Order::maybe_record_order_payment' );
}
add_action( 'woocommerce_order_status_processing', 'eg_do_not_activate_subscription_on_processing', 0 ); // run on priority 0 to trigger before Subscriptions
add_action( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
function wc_subs_suspend_on_cod( $order ) {
if ( ! is_object( $order ) ) {
$order = new WC_Order( $order );
}
foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {
$subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
add_action( 'template_redirect', 'wc_custom_redirect_after_purchase' );
function wc_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && ! empty( $wp->query_vars['order-received'] ) ) {
$order_id = absint( $wp->query_vars['order-received'] );
$order_key = wc_clean( $_GET['key'] );
/**
* Replace {PAGE_ID} with the ID of your page
// Automatically grant membership at registration
function sv_add_membership_at_registration( $user_id ) {
$args = array(
// Enter the ID (post ID) of the plan to grant at registration
'plan_id' => 253,
'user_id' => $user_id,
);
wc_memberships_create_user_membership( $args );
}
add_action( 'user_register', 'sv_add_membership_at_registration', 15 );