Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Remove quantity input field in cart for specific products
*/
function prefix_cart_item_quantity( $product_quantity, $cart_item_key ){
$cart_item = WC()->cart->cart_contents[ $cart_item_key ];
$product_id = $cart_item['data']->get_id();
if( in_array( $product_id, array( 467, 789 ) ) ){
$product_quantity = $cart_item['quantity'];
}
<?php
/**
* Add div inside group wrapper
*/
function prefix_open_group_inner( $group_id, $group, $group_index ) {
echo '<div class="my-group-inner">';
}
add_action( 'pewc_open_group_inner', 'prefix_open_group_inner', 10, 4 );
function prefix_close_group_inner( $group_id, $group, $group_index ) {
<?php
/**
* Filter group wrapper classes
* @param $classes Array
*/
function prefix_filter_group_wrapper_class( $classes, $group_id, $group, $product_id ) {
$classes[] = 'my-new-group-class';
return $classes;
}
add_filter( 'pewc_filter_group_wrapper_class', 'prefix_filter_group_wrapper_class', 10, 4 );
<?php
/**
* Open a new div to wrap multiple groups
* Ensure you update the group ID
*/
function prefix_open_group_wrapper( $group_id, $group, $group_index ) {
if( $group_id == 455 ) {
echo '<div class="my-group-wrapper">';
}
}
<?php
/**
* Enable text values from calculation lookup tables
*/
add_filter( 'pewc_allow_text_calcs', '__return_true' );
<?php
/**
* Array of discount rates
*/
function prefix_discount_rates( $rates, $product_id ) {
$excluded_ids = array( 1234 );
if( in_array( $product_id, $excluded_ids ) ) {
return $rates;
}
$rates = array(
<?php
/**
* Ensure tax isn't added to options with 'value only'
*/
function prefix_check_tax_for_option_price( $check, $option_price, $item ) {
if( ! empty( $item['option_price_visibility'] && $item['option_price_visibility'] == 'value' ) ) {
return false;
}
return $check;
}
<?php
/**
* Filter Bookings discount rates
*/
function prefix_discount_rates( $rates, $product_id ) {
$rates = array(
array(
'rate' => 3,
'after' => 10,
'from' => 'all'
/* Disable checkboxes */
.pewc-group-checkbox .pewc-item-field-wrapper {
pointer-events: none;
}
<?php
/**
* Display remaining quantity on Bookings page
*/
function prefix_display_remaining_quantity() {
$remaining = bfwc_get_max_bookings( get_the_ID() );
printf(
'Places remaining: %s',
$remaining
);