Skip to content

Instantly share code, notes, and snippets.

View prefix_enable_image_editing.php
<?php
/**
* Enable image editing for certain products
*/
function prefix_enable_image_editing( $enabled ) {
$product_id = get_the_ID();
if( in_array( $product_id, array( 123, 456, 789 ) ) {
$enabled = 'yes';
}
return $enabled;
View pewc_rename_uploaded_file.php
<?php
/**
* Fix issue with Divi compatibility
*/
remove_filter( 'sanitize_file_name', 'pewc_rename_uploaded_file' );
View ptuwc_placeholder_label.php
<?php
/**
* Filter the 'Product tags' placeholder
*/
function prefix_ptuwc_taxonomy_label( $label, $filterable_column ) {
if( $filterable_column == 'product_tag' ) {
$label = 'My new placeholder';
}
return $label;
}
View bfwc_auto_set_end.php
<?php
/**
* Display a single calendar
* Only for use with single day bookings
*/
function prefix_auto_set_end( $auto, $product_id ) {
return 'yes';
}
add_filter( 'bfwc_auto_set_end', 'prefix_auto_set_end', 10, 2 );
View filter-field-class.php
<?php
function prefix_filter_single_product_classes( $classes, $item ) {
$classes[] = 'my-new-class';
return $classes;
}
add_filter( 'pewc_filter_single_product_classes', 'prefix_filter_single_product_classes', 10, 2 );
@plugin-republic
plugin-republic / woocommerce-payment-gateway-fee.php
Last active November 13, 2023 20:44
Add a charge to WooCommerce when the customer checks out via PayPal: https://pluginrepublic.com/woocommerce-payment-gateway-based-fees/
View woocommerce-payment-gateway-fee.php
<?php
/**
* Add a fee when the user checks out with PayPal
*/
function wcfad_apply_payment_gateway_fee() {
$payment_method = WC()->session->get( 'chosen_payment_method' );
// Only apply the fee if the payment gateway is PayPal
// Note that you might need to check this slug, depending on the PayPal gateway you're using
if( $payment_method == 'ppec_paypal' ) {
$label = __( 'PayPal fee', 'wcfad' );
@plugin-republic
plugin-republic / simple.php
Created June 17, 2019 15:03
The WooCommerce simple product page
View simple.php
<?php
/**
* Simple product add to cart
*
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/simple.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
View pewc_child_product_independent_quantity.php
<?php
/**
* Force a child product to be automatically selected
*/
function prefix_filter_default_child_independent_quantity( $quantity_field_value, $child_product_id, $item ) {
if( $child_product_id == 9999 ) { // Change this to your child product ID
return 1;
}
return $quantity_field_value;
}
View prefix_adjust_document_item_product_shortcode.php
<?php
/**
* Add add-on data to Germanized for WooCommerce invoices
* You'll also need to add a [document_item_product data="aou_addons"] shortcode under the line item in the invoice template
*/
function prefix_adjust_document_item_product_shortcode( $result, $atts, $document, $shortcodes ) {
if ( $atts['data'] !== 'aou_addons' ) {
return $result;
}
View wcmo_redirect_url.php
<?php
/**
* Find which category is protected by a given password
* @return term_id
*/
function prefix_get_product_category_by_password( $password ) {
$terms = get_terms( array(
'taxonomy' => 'product_cat'
) );
if( $terms ) {