Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Apply the standard booking cost as a fixed cost to a booking, regardless of how long the booking is
*/
function prefix_fixed_booking_cost( $booking_cost, $product_id ) {
$product = wc_get_product( $product_id );
$booking_cost = floatval( bfwc_get_standard_cost( $product ) );
return $booking_cost;
<?php
/**
* Filter Bookings discount rates
* This snippet allows you to set fixed prices for multiple tiers
* In the array below:
* rate refers to the fixed price per unit
* after refers to the number of units where the rate kicks in
* from set to 'all' to apply the rate to the entire booking price
*/
function prefix_discount_rates( $rates, $product_id ) {
<?php
function demo_close_accordion() {
return 'yes';
}
add_filter( 'pewc_close_accordion', 'demo_close_accordion' );
@plugin-republic
plugin-republic / pr_query_attachments.php
Created April 29, 2024 08:43
Query WordPress attachments with no alt text and automatically create alt text using file name
<?php
/**
* Query WordPress attachments with no alt text
* Automatically create alt text using file name
* Remove this snippet once you've run it
*/
function pr_query_attachments() {
if( did_action( 'init' ) > 1 ) {
return;
}
<?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
/**
* 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
/**
* Enable text values from calculation lookup tables
*/
add_filter( 'pewc_allow_text_calcs', '__return_true' );