Skip to content

Instantly share code, notes, and snippets.

View psaikali's full-sized avatar
🥑
WordPress'in & React'in

Pierre Saikali psaikali

🥑
WordPress'in & React'in
View GitHub Profile
@psaikali
psaikali / woocommerce-custom-checkout-fields.php
Created December 28, 2019 13:05
Add custom WooCommerce checkout fields, add an extra fee to the cart, validate the fields before processing the order and save them on the order metadata.
<?php
/**
* Plugin Name: WooCommerce Custom Checkout Fields
* Description: Add some custom "emergency level" extra fields on the WooCommerce Checkout page. Save this custom data in each order metadata.
* Author: Pierre Saïkali
* Author URI: https://saika.li
* Text Domain: wc_ccf
* Domain Path: /languages/
* Version: 1.0.0
* Full Tutorial: https://mosaika.fr/personnaliser-tunnel-commande-woocommerce/
@psaikali
psaikali / cf7-woocommerce-order-field.php
Created December 27, 2019 21:31
Create a new [wc_order] Contact Form 7 field tag which can only accept a valid WooCommerce order number.
<?php
/**
* Plugin Name: Contact Form 7 WooCommerce Order Select Field
* Description: Use the <code>[wc_order]</code> field in CF7 forms
* Author: Pierre Saïkali
* Author URI: https://saika.li
* Text Domain: cf7wcp
* Domain Path: /languages/
* Version: 1.0.0
*/
@psaikali
psaikali / as3cf-update_products_downloadable_files.php
Last active May 21, 2019 09:52
Process WooCommerce products and set correct downloadable files if they've been offloaded by WP Offload Media
<?php
namespace Mosaika;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Register our custom commands.
@psaikali
psaikali / custom_wc_get_products_parameters.php
Last active February 21, 2024 21:21
Ajouter de nouveaux paramètres de requête à wc_get_products()
<?php
namespace Mosaika;
/**
* Handle a custom 'vendor' query var to get products of a specific Vendor.
* Handle a custom 'featured_by_vendor' query var to get featured products of a specific Vendor.
*
* @param array $query_args - WP_Query args
* @param array $query_vars - WC_Product_Query args
@psaikali
psaikali / 1mailchimp-wp-fonction.php
Last active January 20, 2019 16:32
WordPress : comment inscrire un nouvel utilisateur dans une liste MailChimp ?
<?php
namespace MSK\Blog\Mailchimp;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Inscrit un utilisateur dans une liste MailChimp
*
@psaikali
psaikali / inspect-wordpress-hooks.php
Last active January 5, 2019 17:44
List all functions hooked on a specific hook. No need to have the specific hook name, just pass one or multiple strings contained in the hook name.
<?php
/**
* Inspect/list functions called on hooks containing specific term
*
* @param array Array of terms that the hook should contain
* @return array
*/
function inspect_hooks( $terms = [ 'wp_' ] ) {
global $wp_filter;
$related_hooks = [];
@psaikali
psaikali / gravity-forms-process-form-if-matches-acf-option.php
Created January 4, 2019 14:23
Intercept specific Gravity Forms form submission and process it only if it's the one we want
<?php
/**
* Intercept form submission and process it
*/
function gf_intercept_form_submission( $data, $form ) {
if ( (int) $form['id'] !== (int) get_field( 'submit_project_gf_form_id', 'option' ) ) {
return;
}
// Do something with $data
@psaikali
psaikali / acf-gravity-forms-field.php
Created January 4, 2019 13:43
Populate ACF select field options with Gravity Forms to select a specific form
<?php
/**
* Populate ACF select field options with Gravity Forms forms
*/
function acf_populate_gf_forms_ids( $field ) {
if ( class_exists( 'GFFormsModel' ) ) {
$choices = [];
foreach ( \GFFormsModel::get_forms() as $form ) {
$choices[ $form->id ] = $form->title;
@psaikali
psaikali / fix-wordpress-permissions.sh
Last active April 25, 2018 12:53 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
WP_ROOT=$1 # <-- wordpress root directory
@psaikali
psaikali / 8fields_update_erase_data.php
Created March 4, 2018 15:28
Ne pas enregistrer la valeur d'un champ ACF
<?php
// Article/tutoriel complet sur https://mosaika.fr/astuces-developpement-acf/
// Documentation officielle https://www.advancedcustomfields.com/resources/acf-update_value/
/**
* Comparer la valeur de 2 champs pour accepter/refuser leur validation
* Filtre : acf/update_value
*/