Skip to content

Instantly share code, notes, and snippets.

View Inzman's full-sized avatar

Indrek Palm Inzman

  • Tartu, Estonia
View GitHub Profile
<?php
function prefix_update_existing_cart_item_meta() {
$cart = WC()->cart->cart_contents;
foreach( $cart as $cart_item_id=>$cart_item ) {
$cart_item['new_meta_data'] = 'Your stuff goes here';
WC()->cart->cart_contents[$cart_item_id] = $cart_item;
}
WC()->cart->set_session();
}
@maddisondesigns
maddisondesigns / functions.php
Last active March 8, 2025 09:18
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
@alokstha1
alokstha1 / functions.php
Last active December 20, 2023 01:25
Woocommerce hook before checkout page submit and after order created
<?php
//triggers before checkout form is submited but order will be created.
add_action( 'woocommerce_checkout_update_order_meta', 'cpm_woocommerce_checkout_update', 10, 2 );
function cpm_woocommerce_checkout_update($order_id, $data) {
/*write ur code*/
}
@chuckreynolds
chuckreynolds / antispambot-wordpress-shortcode.php
Created April 26, 2017 22:43
Antispambot WordPress shortcode function
<?php
/**
* Hide email from Spam Bots using a shortcode.
* Anti-Spambot Email Shortcode, v1.1.1
* https://wordpress.org/plugins/antispambot
*
* @param array $atts Shortcode attributes. Not used.
* @param string $content The shortcode content. Should be an email address.
*
* @return string The obfuscated email address.
@ControlledChaos
ControlledChaos / README.md
Last active August 5, 2022 15:00
Add data attributes to WordPress image links for use with Fancybox.

Fancybox Data Attributes to Images & Galleries

WordPress Snippet

@yanknudtskov
yanknudtskov / woocommerce-duplicate-skus.sql
Last active July 9, 2024 03:28
Select Duplicate SKUs from WooCommerce Database #woocommerce #mysql
# SELECT any post_status
SELECT meta_value,COUNT(meta_value),GROUP_CONCAT(DISTINCT post_id ORDER BY post_id SEPARATOR ',') post_id
FROM wp_postmeta
WHERE meta_key = '_sku'
AND meta_value != ''
GROUP BY meta_value HAVING COUNT(meta_value) > 1
# SELECT only from products that are already published or in draft
SELECT meta_value,COUNT(meta_value),GROUP_CONCAT(DISTINCT post_id ORDER BY post_id SEPARATOR ',') post_id
FROM wp_postmeta
@eduwass
eduwass / duplicate-post.php
Last active September 17, 2024 15:16
Programmatically duplicating a WordPress post
<?php
/**
* Duplicates a post & its meta and returns the new duplicated Post ID.
*
* @param int $post_id The Post ID you want to clone.
* @return int The duplicated Post ID.
*/
function duplicate_post(int $post_id): int
{
@vanbo
vanbo / wc-add-order-notes-to-admin-emails
Last active November 14, 2022 13:02
WooCommerce: Add Order notes to admin emails
add_action( 'woocommerce_email_order_meta', 'woo_add_order_notes_to_email', 10, 3 );
function woo_add_order_notes_to_email( $order, $sent_to_admin = true, $plain_text = false ) {
// You want to send those only to the Admin
if ( ! $sent_to_admin ) {
return;
}
// You can also check which email you are sending, by checking the order status
// Optional, comment it out, if not needed
@mohammadmursaleen
mohammadmursaleen / gist:9622098e43afdab6025e
Last active October 15, 2021 18:29
Adding custom fields above WOOCOMMERCE add to cart button
<?php
// To add custom data above add to cart button in woocommerce
// step 1
add_action('wp_ajax_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
add_action('wp_ajax_nopriv_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
function wdm_add_user_custom_data_options_callback()
@Zodiac1978
Zodiac1978 / .htaccess
Last active June 5, 2025 14:13
Safer WordPress with these .htaccess additions
# Don't show errors which contain full path diclosure (FPD)
# Use that line only if PHP is installed as a module and not per CGI
# try using a php.ini in that case.
# Change mod_php5.c to mod_php7.c if you are running PHP7
<IfModule mod_php5.c>
php_flag display_errors Off
</IfModule>
# Don't list directories
<IfModule mod_autoindex.c>