Skip to content

Instantly share code, notes, and snippets.

@devinsays
devinsays / update-product-prices.php
Last active June 5, 2023 20:01
Updates product prices via WP CLI script.
<?php
/**
* Updates product prices.
* More about WP CLI scripts:
* https://wptheming.com/2021/05/wp-cli-scripts-and-woocommerce/
*
* wp eval-file update-product-prices.php
*/
$products = get_posts([
@MuhammadSaim
MuhammadSaim / rarreg.key
Last active June 29, 2024 12:25
Step 1: Create a file called rarreg.key Step 2: Paste into the file the raw content of this gist Step 3: Go to Winrar install directory (by default => c:\ProgramFiles\WinRAR\ ) Step 4: Paste the rarreg.key into WinRAR directory Step 5: Enjoy
RAR registration data
WinRAR
Unlimited Company License
UID=4b914fb772c8376bf571
6412212250f5711ad072cf351cfa39e2851192daf8a362681bbb1d
cd48da1d14d995f0bbf960fce6cb5ffde62890079861be57638717
7131ced835ed65cc743d9777f2ea71a8e32c7e593cf66794343565
b41bcf56929486b8bcdac33d50ecf773996052598f1f556defffbd
982fbe71e93df6b6346c37a3890f3c7edc65d7f5455470d13d1190
6e6fb824bcf25f155547b5fc41901ad58c0992f570be1cf5608ba9
@stuartduff
stuartduff / wc-remove-billing-fields-required.php
Last active January 23, 2019 14:41
Removes the required status for all WooCommerce Checkout Billing Fields
/**
* Sets all WooCommerce billing fields to be unrequired.
*/
function wc_unrequire_billing_fields( $fields ) {
$fields['billing_first_name']['required'] = false;
$fields['billing_last_name']['required'] = false;
$fields['billing_company']['required'] = false;
$fields['billing_country']['required'] = false;
$fields['billing_address_1']['required'] = false;
$fields['billing_city']['required'] = false;
@stuartduff
stuartduff / remove-free-shipping-if-coupon-used.php
Created June 14, 2018 10:26
Remove free shipping in WooCommerce if a coupon is applied at checkout
add_filter( 'woocommerce_shipping_packages', function( $packages ) {
$applied_coupons = WC()->session->get( 'applied_coupons', array() );
if ( ! empty( $applied_coupons ) ) {
$free_shipping_id = 'free_shipping:2';
unset($packages[0]['rates'][ $free_shipping_id ]);
}
return $packages;
} );
@Jon007
Jon007 / functions.php
Last active December 4, 2023 08:17
Add default Product Attributes to all WooCommerce products
/*
* Example adds certain named Product Attribute fields to the product Edit screen ready for completion.
* (Pre-requisite )
* This saves the Shop Admin having to add them manually.
*
* Why might you want to do this instead of adding Custom fields? There's plenty of nice documentation on adding custom fields
* for example: http://www.remicorson.com/mastering-woocommerce-products-custom-fields/
*
* Well a Product Attributes are a built in WooCommerce feature, using Terms which are a built in Wordpress feature.
* - no add-ons required
@bekarice
bekarice / wc-add-order-item-meta-to-rest-response.php
Created December 28, 2016 20:18
Example: Add order item meta to WC REST API
<?php // only copy if needed
/**
* Example: Add order meta to the REST API
* WC 2.6+
*
* @param \WP_REST_Response $response The response object.
* @param \WP_Post $post Post object.
* @param \WP_REST_Request $request Request object.
* @return object updated response object
@RiaanKnoetze
RiaanKnoetze / function.php
Created November 4, 2016 05:31
Remove the WooCommerce Dashboard Status widget in WP Admin for all users that don't have "subscriber" role capabilities.
if (current_user_can('subscriber')) {
function remove_dashboard_widgets() {
// remove WooCommerce Dashboard Status
remove_meta_box( 'woocommerce_dashboard_status', 'dashboard', 'normal');
}
add_action('wp_user_dashboard_setup', 'remove_dashboard_widgets', 20);
add_action('wp_dashboard_setup', 'remove_dashboard_widgets', 20);
} // if
@mikaelz
mikaelz / delete-all-woocommerce-products.php
Last active April 30, 2024 06:07
Remove all WooCommerce products from database via SQL
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%')");
$wpdb->query("DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'");
$wpdb->query("DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)");
$wpdb->query("DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_posts WHERE post_type IN ('product','product_variation')");
@dannyconnolly
dannyconnolly / translate_woocommerce.php
Created December 18, 2015 13:22
Change SKU text label in woocommerce to Product Code
function translate_woocommerce($translation, $text, $domain) {
if ($domain == 'woocommerce') {
switch ($text) {
case 'SKU':
$translation = 'Product Code';
break;
case 'SKU:':
$translation = 'Product Code:';
break;
@leowebguy
leowebguy / parallelize.php
Last active August 31, 2020 15:28
Parallelize downloads across hostnames for WordPress. Useful to boost static resources load speed on websites. Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
<?php
/******
Parallelize downloads across hostnames for WordPress.
Useful to boost static resources load speed on websites.
Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
See full post > https://medium.com/p/32e9dc2fec0c
In order to work properly, all subdomains/hostnames MUST have the same structure/path. Ex:
http://mydomain.com/wp-content/uploads/2015/11/myimage.jpg