Skip to content

Instantly share code, notes, and snippets.

View PluginRepublicSupport's full-sized avatar

PluginRepublicSupport

View GitHub Profile
@PluginRepublicSupport
PluginRepublicSupport / number.php
Last active March 6, 2024 14:22
A number field template
<?php
/**
* A number field template
* @since 2.0.0
* @package WooCommerce Product Add-Ons Ultimate
*/
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) {
exit;
@PluginRepublicSupport
PluginRepublicSupport / pewc_range_field_input_type.php
Created March 6, 2024 14:20
Add your custom logic here to determine the input type
<?php
add_filter('pewc_number_field_input_type', 'range_number_field_input_type', 10, 3);
function range_number_field_input_type($input_type, $product_id, $item)
{
// Check if the enable_range_slider is set to 'checked'
$enable_range_slider = isset( $item['enable_range_slider'] ) ? $item['enable_range_slider'] : '';
if ($enable_range_slider == '1') {
@PluginRepublicSupport
PluginRepublicSupport / pew_custom_checkbox_param.php
Created March 6, 2024 14:19
Add a range parameter to add-on field settings if the field type is "number"
<?php
/**
* Add a custom checkbox parameter to number field settings
*/
function pew_custom_checkbox_param( $group_key, $item_key, $item, $post_id ) {
$field_type = isset( $item['field_type'] ) ? $item['field_type'] : '';
@PluginRepublicSupport
PluginRepublicSupport / prefix_html_in_description.php
Created January 30, 2024 12:38
Allow HTML content in field description
<?php
/**
* Allow HTML content in field description
*/
function prefix_html_in_description( $description, $item, $additional_info='' ) {
$field_description = ! empty( $item['field_description'] ) ? $item['field_description'] : '';
// Allow HTML content in the field description
$allowed_tags = wp_kses_allowed_html( 'post' );
$field_description = wp_kses( $field_description, $allowed_tags );
@PluginRepublicSupport
PluginRepublicSupport / wcmo_fibosearch.php
Last active January 16, 2024 06:42
Compatibility between WooCommerce Members Only and FiboSearch
<?php
/**
* Hide products restricted by WooCommerce Members Only from FiboSearch results
*/
function wcmo_fibosearch_remove_restricted_products( $products ) {
if ( ! empty( $products ) ) {
$tmp = array();
foreach ( $products as $product ) {
if ( ! wcmo_is_product_restricted( $product->ID ) ) {
$tmp[] = $product;
@PluginRepublicSupport
PluginRepublicSupport / wcfad_min_max_total_step.php
Last active January 16, 2024 06:42
Allow decimals in the min/max total tier fields for Order Total and Discount on Spend rules in WooCommerce Fees and Discounts plugin
<?php
add_filter( 'wcfad_tier_min_step', function( $step ) { return '0.01'; });
add_filter( 'wcfad_tier_max_step', function( $step ) { return '0.01'; });
@PluginRepublicSupport
PluginRepublicSupport / preview_colorpicker_palette.php
Created November 10, 2023 12:34
Set predefined color palettes in the color picker
<?php
add_action( 'wp_footer', function() {
?>
<script>
jQuery(document).ready(function($) {
let apc = $('.apaou-customer-fields').find('.apaou-color-field').get(0);
// Specify your color palettes here
let colorPalettes = ['#000', '#000', '#000', '#fff', '#ff0'];
@PluginRepublicSupport
PluginRepublicSupport / exclude_addons_cost_in_coupons.php
Last active October 27, 2023 08:59
Exclude add-ons cost in coupon discounts
<?php
/**
* Exclude add-ons cost in coupon discounts
* @return discount amount
*/
add_filter( 'woocommerce_coupon_get_discount_amount', function( $amount, $discounting_amount, $cart_item, $single, $coupon ) {
$apply_coupon = array( '1097_1772' ); // GroupId_FieldId
@PluginRepublicSupport
PluginRepublicSupport / pewc_child_quantity_cart.php
Created October 26, 2023 15:54
Edit child product quantity in cart
<?php
// Editable child quantity in cart when set to independent
add_filter('pewc_disable_child_quantities', '__return_false');
@PluginRepublicSupport
PluginRepublicSupport / wcfad_pewc_adjust_field_prices.php
Created October 24, 2023 08:07
If both Product Add-Ons Ultimate and Fees and Discounts are installed, and "Apply User Role Pricing to add-on field prices" is enabled, you can override this on a per-field basis using the "wcfad_pewc_adjust_field_prices" filter
<?php
add_filter( 'wcfad_pewc_adjust_field_prices', 'custom_wcfad_pewc_adjust_field_prices', 10, 3 );
function custom_wcfad_pewc_adjust_field_prices( $adjust, $item, $product_id ) {
// if field price is a percentage of the product price, do not adjust
if ( $item['field_percentage'] ) {
$adjust = false;
}
return $adjust;
}