Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Filter price for non-logged-in users
*/
function pr_demo_get_price_html( $price, $product ) {
if( !is_user_logged_in() ) {
// Add a custom message here to display instead of the price
return __( 'Price on application', 'your_textdomain' );
}
return $price;
<?php
/**
* Hide products with specific IDs
* Edit line 7 with the IDs you want to hide prices for
*/
add_filter( ‘woocommerce_get_price_html’, function( $price, $product ) {
if( is_admin() ) return $price;
$product_ids = array( 1234, 5678 );
if( in_array( $product->get_id(), $product_ids ) ) {
return '';
<?php
add_filter( ‘woocommerce_get_price_html’, function( $price ) {
if ( is_admin() ) return $price;
return ”;
});
add_filter( ‘woocommerce_cart_item_price’, ‘__return_false’ );
add_filter( ‘woocommerce_cart_item_subtotal’, ‘__return_false’ );
<?php
add_filter( ‘woocommerce_get_price_html’, function( $price ) {
if ( is_admin() ) return $price;
return ”;
});
<?php
/**
* Exclude child products from coupons
*/
add_filter( 'woocommerce_coupon_is_valid_for_product', function( $valid, $product, $coupon, $values ) {
if ( ! empty( $values['product_extras']['price_with_extras_discounted'] ) ) {
$price = $values['product_extras']['original_price'];
$price_discounted = $values['product_extras']['price_with_extras_discounted'];
if ( $price != $price_discounted ) {
$valid = false;
<?php
/**
* Ensure that products with user ID permissions override any global settings
*/
add_filter( 'wcmo_always_show_user_products', '__return_true' );
<?php
function pewc_ajax_add_child_product_to_cart() {
$result = WC()->cart->add_to_cart( intval( $_POST['product_id'] ), intval( $_POST['quantity'] ) );
$result ? wp_send_json_success() : wp_send_json_error();
}
add_action('wp_ajax_pewc_add_child_product_to_cart', 'pewc_ajax_add_child_product_to_cart');
add_action('wp_ajax_nopriv_pewc_add_child_product_to_cart', 'pewc_ajax_add_child_product_to_cart');
<?php
/**
* Automatically populate a field with user data
* Enter the user field in the 'Default' field
* Wrapped in {}
* E.g. {first_name}
*/
function junhee_populate_user_field( $value, $id, $item, $posted ) {
if( is_user_logged_in() ) {
<?php
function prefix_external_registration_approval_message( $message, $url, $user_id ) {
if( ! apply_filters( 'wcmo_allow_external_approval', false ) ) {
return $message;
}
$user_data = get_userdata( $user_id );
$message .= '<p>User email: ' . $user_data->user_email . '</p>';
return $message;
<?php
add_filter( 'wcmo_allow_external_approval', '__return_true' );