Skip to content

Instantly share code, notes, and snippets.

Avatar

WooCommerce.com Documentation woogist

View GitHub Profile
View functions.php
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 Jul 31, 2015
Change the "Add to Cart" text on the single product page based on the product ID
View functions.php
/**
* 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 );
View functions.php
add_filter( 'wc_session_expiring', create_function( '', 'return "2 * 60";' ) );
add_filter( 'wc_session_expiration', create_function( '', 'return "3 * 60";' ) );
View style.css
.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;
}
View functions.php
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
View functions.php
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 ) );
View functions.php
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
View functions.php
// 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 );
View gist:365a4602018b6c1df39a
$args = array(
// Enter the ID (post ID) of the plan to grant access to
'plan_id' => 253,
'user_id' => $user_id,
);
wc_memberships_create_user_membership( $args );
View functions.php
add_filter( '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 ) );