Skip to content

Instantly share code, notes, and snippets.

<?php
// Update shipping class if a specific field has any value
// Uncomment line below if you want to check the field for a specific value
add_action( 'woocommerce_before_calculate_totals', function( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
$target_field_id = 1642; // the field ID
$shipping_class = 'easy'; // the shipping class slug
<?php
remove_action( 'pewc_after_group_wrap', 'pewc_display_clear_all_button', 21 );
// Place Clear All Options above totals summary
add_action( 'pewc_after_group_wrap', 'pewc_display_clear_all_button', 0, 3 );
// Place Clear All Options above all fields
// add_action( 'pewc_start_groups', function( $args ) {
// pewc_display_clear_all_button( $args[0], null, array() );
// } );
<?php
/**
* Flat rate with daily overage for Bookings for WooCommerce
*
* When a product has the "Flat rate" option enabled, charges the flat rate
* for bookings up to $min_days, then adds $daily_rate
* for each additional day beyond that.
*
* Add to your theme's functions.php or a site-specific plugin.
*
<?php
/**
* Set migration to done for Dynamic Pricing and Discount Rules
*/
add_filter( 'wcfad_assume_migration_done', '__return_true' );
<?php
/**
* Subtract last day's cost from daily booking
* Requires bookings to be a minimum of 2 days
*/
function demo_dont_charge_last_day( $booking_cost, $product_id ) {
$std_cost = bfwc_get_standard_cost( $product_id );
$booking_cost = $booking_cost - $std_cost;
return $booking_cost;
}
<?php
add_action( 'wp_footer', function(){
?>
<script>
jQuery( document ).ready( function(){
jQuery( document.body ).on( 'woosq_loaded', function( event, id ){
jQuery( 'body' ).trigger( 'pewc_check_conditions' ).trigger('pewc_trigger_calculations');
jQuery( 'body' ).trigger( 'pewc_reinitiate_js_validation' );
jQuery( 'body' ).trigger( 'pewc_attach_form_cart_input_change' );
jQuery( 'body' ).trigger( 'pewc_trigger_initial_check' );
<?php
/**
* If a product has an alternative featured image, display that on the archive page
*/
function pr_demo_product_get_image( $image, $product, $size, $attr, $placeholder ) {
if( is_product() ) {
// We're on a product page so just return the image
return $image;
}
$product_id = $product->get_id();
.pewc-has-hex .pewc-radio-images-wrapper img {
visibility: visible;
height: auto;
}
.pewc-hex {
display: none;
}
<?php
/**
* Filter the available fonts for each text preview field
* List fonts in arrays using 'abel' => 'Abel' key / value pairs
* Update the field IDs to match your own
*/
function demo_filter_all_fonts( $all_fonts, $available_fonts, $field ) {
// Update the field IDs below to match your field IDs
if( $field['field_id'] == 1209 ) {
<?php
/**
* Add a shortcode using a hook
*/
function pr_add_shortcode_after_product_summary() {
echo do_shortcode( '[product_category category="hoodies" columns="3" limit="6"]' );
}
add_action( 'woocommerce_after_single_product_summary', 'pr_add_shortcode_after_product_summary', 5 );