Skip to content

Instantly share code, notes, and snippets.

.ptuwc_table_container table thead tr th, .ptuwc_table_container table tbody tr td {
padding-top: 16px;
padding-bottom: 16px;
}
<?php
/**
* Filter product if user not logged in
*/
function pr_demo_is_purchasable( $purchasable, $product ) {
if( !is_user_logged_in() ) {
return false;
}
return $purchasable;
}
<?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() ) {