Skip to content

Instantly share code, notes, and snippets.

View romanrehacek's full-sized avatar

Roman Rehacek romanrehacek

View GitHub Profile

🚀 Zed IDE: WordPress + WooCommerce + ACF Setup

This guide resolves Undefined function errors (e.g., get_header, get_field, wc_get_product) in Zed IDE when working inside a specific WordPress directory (such as a theme or plugin) where the full WordPress core is not loaded or indexed.

This setup ensures that WordPress, WooCommerce, and ACF functions are properly recognized by the PHP language server.


🛠 1. Prepare the Stub Directory (User: [user])

@romanrehacek
romanrehacek / gist:1a9b3c3d3e82c1925afd43b7b897ef0a
Created July 3, 2025 09:10
Delete all orders and customers from Woocommerce
-- Step 1 - Delete orders
-- Disable foreign key checks temporarily
SET FOREIGN_KEY_CHECKS = 0;
-- Delete order items
DELETE FROM wp_woocommerce_order_items WHERE order_id IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order');
-- Delete order item meta
DELETE FROM wp_woocommerce_order_itemmeta WHERE order_item_id IN (SELECT order_item_id FROM wp_woocommerce_order_items WHERE order_id IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order'));
-- Delete order notes
DELETE FROM wp_comments WHERE comment_post_ID IN (SELECT ID FROM wp_posts WHERE post_type = 'shop_order');
@romanrehacek
romanrehacek / dump.sh
Created May 7, 2019 12:54
Backup all databases in separate files
#!/bin/sh
## backup each mysql db into a different file, rather than one big file
## as with --all-databases. This will make restores easier.
## To backup a single database simply add the db name as a parameter (or multiple dbs)
## Putting the script in /var/backups/mysql seems sensible... on a debian machine that is
## Create the user and directories
# mkdir -p /var/backups/mysql/databases
# useradd --home-dir /var/backups/mysql --gid backup --no-create-home mysql-backup
## Remember to make the script executable, and unreadable by others
@romanrehacek
romanrehacek / functions.php
Created April 19, 2017 13:23
Mailchimp WP Ajax Newsletter singup form
<?php
add_action( 'wp_ajax_newsletter_form', 'newsletter_form' );
add_action( 'wp_ajax_nopriv_newsletter_form', 'newsletter_form' );
function newsletter_form() {
$api_key = 'API_KEY';
$datacenter = 'us15';
$list_id = 'LIST_ID';
@romanrehacek
romanrehacek / nav-widget-walker.php
Created March 25, 2017 16:45
Use custom walker or other wp_nav_menu() attributes for widget nav menu
<?php
add_filter( 'widget_nav_menu_args', 'my_custom_widget_nav_menu_args', 10, 4 );
function my_custom_widget_nav_menu_args( $nav_menu_args, $nav_menu, $args, $instance ) {
// use only for certain widget area
if ( in_array( $args['id'], array( 'footer_2' ) ) ) {
$nav_menu_args['walker'] = new My_Walker();
@romanrehacek
romanrehacek / paginate_links.php
Created March 11, 2017 19:32
Paginate links in UL list
@romanrehacek
romanrehacek / excerpt.php
Last active March 11, 2017 19:29
Wordpress custom excerpt
<?php
/**
* Custom excerpt that displays the exact number of words.
*
* @param text $text Post excerpt or content.
* @param int $count Optional. Number of words.
* @return text Excerpt text.
*/
function custom_excerpt( $text, $count = 150 ) {
if ( empty( $text ) ) {
@romanrehacek
romanrehacek / search.php
Last active December 6, 2016 15:14
Add wordpress meta values to search query
<?php
/**
* adds meta values on search query
*
* @param object $query
*
**/
if ( !function_exists('my_posts_where_request') ) {
function my_posts_where_request( $where ) {