Skip to content

Instantly share code, notes, and snippets.

View unostar's full-sized avatar

Alexei Danilchik unostar

View GitHub Profile
<?php
/**
* Specify the default quantities here
* You'll need to update the child product IDs to match yours
*/
function florian_child_quantity( $quantity_field_value, $child_product_id, $item ) {
if( $child_product_id == 267 ) {
$quantity_field_value = 3;
}
if( $child_product_id == 269 ) {
<?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;
}
@antonmaju
antonmaju / gform_s3_uploader.php
Last active January 2, 2023 21:11
Gravity form filter to handle file upload integration with WP Offload S3 Lite plugin. Adapted from https://wordpress.org/support/topic/support-for-gravity-forms-uploads.
<?php
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
require_once WP_CONTENT_DIR.'/plugins/amazon-web-services/vendor/aws/aws-autoloader.php';
use \Aws\S3\S3Client;
add_filter('gform_upload_path', 'gform_change_upload_path', 10, 2);
add_action('gform_after_submission', 'gform_submit_to_s3', 10, 2);
//change gravity form upload path to point to S3
@neilgee
neilgee / addinfunctions.php
Last active January 30, 2023 20:34
Gravity Form Word Count
<?php
/* Gravity Forms Word Count Script */
function els_load_scripts() {
wp_enqueue_script('gravity-forms-word-count', get_stylesheet_directory_uri() . '/js/jquery.gravity_word_count.js', array('jquery'), '0.1', true);
}
add_action('wp_enqueue_scripts', 'els_load_scripts');
/*Then in the form, for fields that need the word count, add the class ‘els-word-count[300].' Change [300] as needed for the maximum words that can be added to that particular field.*/
/*Source http://www.gravityhelp.com/forums/topic/maximum-word-count#post-149331*/
@amdrew
amdrew / functions.php
Last active January 13, 2023 00:59
Easy Digital Downloads - Start to finish example of 1. Adding a phone number field at checkout 2. Making the phone field required 3. Showing the phone field on the "view order details" screen 4. Adding a new {phone} email tag to show the phone number in either the standard purchase receipt or admin notifications
<?php
/**
* Display phone number field at checkout
* Add more here if you need to
*/
function sumobi_edd_display_checkout_fields() {
// get user's phone number if they already have one stored
if ( is_user_logged_in() ) {
@CMCDragonkai
CMCDragonkai / wp-config.php
Last active November 5, 2017 03:30
Wordpress: Automatic Url and Content Dir/Url Detection for Wordpress Composer Installs. Add to the top of the wp-config.php script.
<?php
/**
* Automatic Url + Content Dir/Url Detection for Wordpress
*/
$document_root = rtrim(str_replace(array('/', '\\'), '/', $_SERVER['DOCUMENT_ROOT']), '/');
$root_dir = str_replace(array('/', '\\'), '/', __DIR__);
$wp_dir = str_replace(array('/', '\\'), '/', __DIR__ . '/wp');
$wp_content_dir = str_replace(array('/', '\\'), '/', __DIR__ . '/wp-content');
@larchanka
larchanka / uniqid.js
Last active October 27, 2019 08:51
JavaScript function that copies functionality of PHP's 'uniqid'.
(function () {
this.uniqid = function (pr, en) {
var pr = pr || '', en = en || false, result;
this.seed = function (s, w) {
s = parseInt(s, 10).toString(16);
return w < s.length ? s.slice(s.length - w) : (w > s.length) ? new Array(1 + (w - s.length)).join('0') + s : s;
};
result = pr + this.seed(parseInt(new Date().getTime() / 1000, 10), 8) + this.seed(Math.floor(Math.random() * 0x75bcd15) + 1, 5);