Skip to content

Instantly share code, notes, and snippets.

@swoboda
swoboda / gravity-forms-option-groups.php
Created May 26, 2020 21:26
Option groups in the Gravity Forms drop down field
<?php
// Do NOT include the opening php tag
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field ) {
if ( $field->get_input_type() == 'select' ) {
$choice_value = rgar( $choice, 'value' );
if ( $choice_value === 'optgroup-start' ) {
return sprintf( '<optgroup label="%s">', esc_html( $choice['text'] ) );
} elseif ( $choice_value === 'optgroup-end' ) {
return '</optgroup>';
@swoboda
swoboda / disable-translation-updates.php
Last active September 6, 2023 09:06 — forked from r-a-y/bp-disable-translation.php
Disable automatic plugins translations by WordPress.org.
<?php
/*
Plugin Name: Disable Translation Updates
Description: Disables automatic plugins translations by WordPress.org.
Author: wpdesk
License: GPLv2 or later
*/
add_filter( 'auto_update_translation', 'wpdesk_disable_translation_updates', 10, 2 );
/**
@swoboda
swoboda / fcf-wlasna-walidacja-nip.php
Last active March 17, 2023 08:01
Flexible Checkout Fields - Walidacja polskiego numeru NIP
<?php
// NIE kopiuj powyższego tagu otwierającego php
/**
* Funkcja do walidacji polskiego numeru NIP
*
*/
function wpdesk_fcf_validate_nip( $field_label, $value ) {
$valid = false;
@swoboda
swoboda / set-dashboard-meta-order.php
Created June 27, 2022 07:11
Make sure our widget is always on top
<?php
add_action( 'admin_init', 'set_dashboard_meta_order' );
/**
* Make sure our widget is always on top
*
*/
function set_dashboard_meta_order() {
$user_id = get_current_user_id();
$user_metabox_order = get_user_meta( $user_id, 'meta-box-order_dashboard' );
@swoboda
swoboda / fcf-custom-validation-number.php
Created April 11, 2018 16:24
Custom Number Validation for WooCommerce Flexible Checkout Fields
<?php
// Do NOT include the opening php tag
/**
* Function to validate the number
*
*/
function wpdesk_fcf_validate_number( $field_label, $value ) {
if ( ! ( ( is_numeric( $value ) ? intval( $value ) == $value : false ) ) ) {
wc_add_notice( sprintf( '%s is not a valid number.', '<strong>' . $field_label . '</strong>' ), 'error' );
@swoboda
swoboda / subscription-auto-renew.php
Created July 18, 2020 17:48
WIP: AutomateWoo Trigger for Auto Renew Toggle
<?php
/**
* This is an example trigger that is triggered via a WordPress action and includes a user data item.
* Trigger with: do_action('my_custom_action', $user_id );
*/
class WPDesk_AutomateWoo_Subscription_Auto_Renew_Trigger extends AutomateWoo\Trigger {
/** @var array - Define which data items are set by this trigger, this determines which rules and actions will be available */
public $supplied_data_items = array( 'customer', 'subscription' );
@swoboda
swoboda / hide_shipping_when_free_is_available.php
Last active July 13, 2020 22:30
hide_shipping_when_free_is_available
<?php
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
/**
* Hide shipping rates when free shipping is available: https://docs.woothemes.com/document/hide-other-shipping-methods-when-free-shipping-is-available/
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
* @return array of modified rates
@swoboda
swoboda / wpdesk-checkout-steps.php
Created June 19, 2020 07:48
Checkout steps in WP Desk Theme
<?php
add_action( 'genesis_after_header', 'wpdesk_checkout_steps', 25 );
/**
* Checkout Steps
*
*/
function wpdesk_checkout_steps() {
global $wp;
@swoboda
swoboda / functions.php
Created October 23, 2019 13:21
Allow Flexible Pricing sales display on non-WooCommerce pages
<?php
// Do NOT include the opening php tag
add_filter( 'wc_flexible_pricing_on_get_price', 'wpdesk_wc_flexible_pricing_on_get_price' );
/**
* Allow Flexible Pricing sales on non-WooCommerce pages
*
*/
function wpdesk_wc_flexible_pricing_on_get_price( $on_get_price ) {
if ( is_page() ) {
@swoboda
swoboda / gravity-forms-notification-help-scout-api-error.php
Created October 15, 2019 14:31
Programmatically Trigger Gravity Forms Notification on Help Scout Error
<?php
// Do NOT include the opening php tag
add_action( 'gform_gravityformshelpscout_post_process_feed', 'wpdesk_helpscout_authentication_mail', 10, 4 );
/**
* Email notification to admin about Gravity Forms Help Scout API authentication problem and create Help Scout conversation
*
*/
function wpdesk_helpscout_authentication_mail( $feed, $entry, $form, $addon ) {