Skip to content

Instantly share code, notes, and snippets.

@plugin-republic
plugin-republic / bfwc-flat-rate-with-daily-surcharge.php
Created November 19, 2026 12:27
Bookings for WooCommerce: flat rate for the first 4 days, then +5% of the standard price per extra day
<?php
/**
* Bookings for WooCommerce: flat rate for the first 4 days, then each extra day adds 5% of the standard price.
*
* Setup: tick Flat rate on the product, set the Standard price, and remove any Discounts rows.
* Example with a standard price of 10: 1-4 days = 10.00, 5 days = 10.50, 8 days = 12.00
*/
add_filter( 'bfwc_discount_rates', function( $discounts, $product_id ) {
if ( ! bfwc_is_flat_rate( $product_id ) ) {
return $discounts;
@plugin-republic
plugin-republic / pewc-wpml-translate-product-level-global-groups.php
Created November 16, 2026 08:32
WooCommerce Product Add-Ons Ultimate + WPML: load translated global groups assigned at product level
<?php
/**
* WooCommerce Product Add-Ons Ultimate + WPML
* Load the translated version of global groups that are assigned on the product itself.
* Add to your child theme's functions.php or a code snippets plugin.
*
* Requirements:
* - In WPML > Settings > Custom Fields Translation, set 'pewc_global_groups_by_product' to "Copy".
* - Each translated global group needs its own fields, conditions and calculations.
*/
<?php
<?php
/**
* Snippet: Choose the pricing display per product in WooCommerce Product Add-Ons Ultimate.
*
* List product IDs in the arrays below to set how prices are shown on each product page:
*
* - 'totals' : the standard totals fields (Product total, Options total, Grand total)
* - 'summary' : the summary panel only (no totals fields underneath)
* - 'none' : no pricing summary at all (no summary panel, no totals fields)
<?php
/**
* Variable Select layout: show the attribute name and value in the variation dropdown,
* e.g. 'Magazijn: Hillegom (137375-A)'
*/
function prefix_variable_select_variation_name_only( $name, $product, $option_price = false, $item = false ) {
if ( empty( $item['products_layout'] ) || 'variable-select' !== $item['products_layout'] ) {
return $name;
}
<?php
/**
* WooCommerce Product Add-Ons Ultimate: show a custom label for specific
* linked products in Products fields (e.g. "Long Traction Bar" -> "Long Bed").
*
* Key = product ID (use the variation ID for a specific variation)
* Value = label the customer sees
*/
function prefix_pewc_child_product_aliases() {
return array(
<?php
/**
* Force Booking products to be treated as shippable (override the plugin's
* hardcoded set_virtual( true ) on WC_Product_Booking), so WooCommerce's own
* shipping logic — including the Blocks/Store API checkout, which doesn't
* reliably respect the bfwc_hide_shipping_fields filter — sees them as
* non-virtual and shows shipping fields.
*/
add_filter( 'woocommerce_product_get_virtual', 'my_bfwc_booking_not_virtual', 10, 2 );
add_filter( 'woocommerce_product_variation_get_virtual', 'my_bfwc_booking_not_virtual', 10, 2 );
<?php
/**
* Dequeue dropzone sitewide
*/
add_action( 'wp_print_scripts', 'my_dequeue_pewc_dropzone', 100 );
add_action( 'wp_print_styles', 'my_dequeue_pewc_dropzone', 100 );
function my_dequeue_pewc_dropzone() {
wp_dequeue_script( 'pewc-dropzone' );
wp_deregister_script( 'pewc-dropzone' );
<?php
/**
* Snippet: Add a 'Shipping speed' radio field (Standard / Express) to the checkout page,
* inside the order review table immediately below the subtotal row and above the
* shipping/payment method options.
*
* Selecting 'Express' adds a 15% fee based on the cart's current total.
* The field is saved to the order as post meta and shown on the admin order screen.
*
* Usage: add this file as an mu-plugin, or require it from your theme/child-theme
<?php
add_filter( 'woocommerce_order_item_display_meta_value', 'my_pewc_hide_field_value_by_type', 20, 3 );
function my_pewc_hide_field_value_by_type( $display_value, $meta, $order_item ) {
if ( ! is_admin() ) {
return $display_value;
}
// Field types to hide the entered value for (price-only display)
$target_types = array( 'radio-group', 'calculation' );
<?php
/**
* Change day into night
*/
function my_bfwc_filter_unit_labels( $labels ) {
$labels['day'] = array(
'single' => __( 'Night', 'bfwc' ),
'plural' => __( 'Nights', 'bfwc' ),
);
return $labels;