Skip to content

Instantly share code, notes, and snippets.

@bekarice
Last active February 4, 2019 22:42
Show Gist options
  • Save bekarice/6e4b69698952c61b86a0 to your computer and use it in GitHub Desktop.
Save bekarice/6e4b69698952c61b86a0 to your computer and use it in GitHub Desktop.
WooCommerce Memberships: Change the price for purchase-restricted products that non-members will see
<?php
/**
* Modify membership product pricing display for non-members
* changes pricing display if purchasing is restricted to members;
* active members will see the price instead of a message
*
* @param string $price the WC price HTML
* @return string $price the updated price HTML
*/
function sv_change_member_product_price_display( $price ) {
// bail if Memberships isn't active
if ( ! function_exists( 'wc_memberships' ) ) {
return $price;
}
// get any active user memberships (requires Memberships 1.4+)
$user_id = get_current_user_id();
$args = array(
'status' => array( 'active', 'complimentary', 'pending' ),
);
$active_memberships = wc_memberships_get_user_memberships( $user_id, $args );
// only proceed if the user has no active memberships
if ( empty( $active_memberships ) ) {
// change price display if purchasing is restricted
if ( wc_memberships_is_product_purchasing_restricted() ) {
$price = 'Price for members only';
}
}
return $price;
}
add_filter( 'woocommerce_get_price_html', 'sv_change_member_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'sv_change_member_product_price_display' );
@VT18472
Copy link

VT18472 commented May 25, 2018

Bekarice, this does not appear to work anymore. Are you able to provide an update? Thanks in advance for any help you can provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment