Skip to content

Instantly share code, notes, and snippets.

View hslaszlo's full-sized avatar

Laszlo Sebestyen Horvath hslaszlo

View GitHub Profile
@hslaszlo
hslaszlo / wc-delete-all-products.sql
Created June 14, 2023 12:41 — forked from twmbx/wc-delete-all-products.sql
WooCommerce Delete All Products, Product Attachments and custom Product Attributes
-- Products
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';
@hslaszlo
hslaszlo / add-gtm-wp.php
Created January 19, 2023 14:28 — forked from jsn789/add-gtm-wp.php
Add Google Tag Manager through functions.php in WordPress
/* Add Google Tag Manager javascript code as close to
the opening <head> tag as possible
=====================================================*/
function add_gtm_head(){
?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
@hslaszlo
hslaszlo / functions.php
Created June 15, 2021 14:57 — forked from Clorith/functions.php
WordPress filter for adding responsive wrapper to embedded content
<?php
/**
* Filter for adding wrappers around embedded objects
*/
function responsive_embeds( $content ) {
$content = preg_replace( "/<object/Si", '<div class="embed-container"><object', $content );
$content = preg_replace( "/<\/object>/Si", '</object></div>', $content );
/**
* Added iframe filtering, iframes are bad.
@hslaszlo
hslaszlo / functions.php
Created April 12, 2019 08:13 — forked from NaszvadiG/functions.php
Szükségtelen képméretek eltávolítása WP-ből
<?php
function remove_unused_image_sizes()
{
remove_image_size( 'image-size-150x150' );
remove_image_size( 'image-size-550x550' );
remove_image_size( 'image-size-550x550-@2x' );
}
@hslaszlo
hslaszlo / remove-all-product-categories-tags.php
Created August 31, 2018 13:14 — forked from mikaelz/remove-all-product-categories-tags.php
Remove all WooCommerce product categories and tags
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE a,c FROM wp_terms AS a
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_tag'");
$wpdb->query("DELETE a,c FROM wp_terms AS a
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
@hslaszlo
hslaszlo / Single.php
Created August 23, 2018 08:56 — forked from trueqap/Single.php
WordPress Facebook HTTPS like probléma megoldása
<?php
global $post;
$ssl_valtas_datuma = strtotime( "2018-08-22" );
$post_datum = strtotime( $post->post_date );
if ( $ssl_valtas_datuma >= $post_datuma ) {
$url_cim = get_permalink();
$url_cim = str_replace('https','http',$url_cim);
} else {
@hslaszlo
hslaszlo / functions.php
Created February 23, 2018 15:49 — forked from jameskoster/functions.php
WooCommerce - Reorder product tabs
add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 );
function woo_reorder_tabs( $tabs ) {
$tabs['reviews']['priority'] = 5; // Reviews first
$tabs['description']['priority'] = 10; // Description second
$tabs['additional_information']['priority'] = 15; // Additional information third
return $tabs;
}
@hslaszlo
hslaszlo / hide_admin.php
Created January 28, 2018 07:24 — forked from trueqap/hide_admin.php
Hide admin for NON-ADMIN users WordPress - Redirect non-admin users to home page
<?php
add_action( 'admin_init', 'redirect_non_admin_users' );
function redirect_non_admin_users() {
if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_redirect( home_url() );
exit;
}
}
@hslaszlo
hslaszlo / functions.php
Created December 21, 2017 07:35 — forked from dleone81/functions.php
Woocommerce get product type
/**
* is_type can be simple, variable, grouped, external
* woocommerce_single_product_summary is hook!
* Put this into your functions.php (child-theme)
**/
add_action( 'woocommerce_single_product_summary', 'get_product_type', 5 );
function get_product_type() {
global $post;
if( function_exists('get_product') ){
$product = get_product( $post->ID );
@hslaszlo
hslaszlo / gist:012f280c8c2a63e0d4dd035bf6108166
Created July 17, 2016 08:20 — forked from corsonr/gist:6138666
WooCommerce - List products by attribute (multiple values), ex: [woo_products_by_attributes attribute="colour" values="red,black" per_page="5"]
<?php
/**
* Plugin Name: WooCommerce - List Products by Attributes
* Plugin URI: http://www.remicorson.com/list-woocommerce-products-by-attributes/
* Description: List WooCommerce products by attributes using a shortcode, ex: [woo_products_by_attributes attribute="colour" values="red,black" per_page="5"]
* Version: 1.0
* Author: Remi Corson
* Author URI: http://remicorson.com
* Requires at least: 3.5
* Tested up to: 3.5