Skip to content

Instantly share code, notes, and snippets.

View tallesairan's full-sized avatar
🏠
Working from home

Talles Airan tallesairan

🏠
Working from home
View GitHub Profile
@tallesairan
tallesairan / tab.js
Last active October 26, 2017 12:57
go to last tab after reload page bootstrap
$(function() {
// for bootstrap 3 use 'shown.bs.tab', for bootstrap 2 use 'shown' in the next line
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
// save the latest tab; use cookies if you like 'em better:
localStorage.setItem('lastTab', $(this).attr('href'));
});
// go to the latest tab, if it exists:
var lastTab = localStorage.getItem('lastTab');
if (lastTab) {
@tallesairan
tallesairan / geocode.php
Last active April 17, 2018 19:36
Get city and state via google geocode api using latitude and longitude
<?php
function simpleCachedCurl($url) {
$hash = md5($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
#curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, "utf-8" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
@tallesairan
tallesairan / deleteallOrders.sql
Created May 18, 2018 17:18
Delete all orders from WooCommerce
DELETE FROM wpcs_woocommerce_order_itemmeta;
DELETE FROM wpcs_woocommerce_order_items;
DELETE FROM wpcs_comments WHERE comment_type = 'order_note';
DELETE FROM wpcs_postmeta WHERE post_id IN ( SELECT ID FROM wpcs_posts WHERE post_type = 'shop_order' );
DELETE FROM wpcs_posts WHERE post_type = 'shop_order';
@tallesairan
tallesairan / select2 select de estados.html
Created May 25, 2018 13:29
select2 select de estados
[select your-state "Selecione seu estado" "AC|Acre" "AL|Alagoas" "AP|Amapá" "AM|Amazonas" "BA|Bahia " "CE|Ceará" "DF|Distrito Federal " "ES|Espírito Santo" "GO|Goiás" "MA|Maranhão" "MT|Mato Grosso" "MS|Mato Grosso do Sul" "MG|Minas Gerais" "PA|Pará" "PB|Paraíba" "PR|Paraná" "PE|Pernambuco" "PI|Piauí" "RJ|Rio de Janeiro" "RN|Rio Grande do Norte" "RS|Rio Grande do Sul" "RO|Rondônia" "RR|Roraima" "SC|Santa Catarina" "SP|São Paulo" "SE|Sergipe" "TO|Tocantins"]
@tallesairan
tallesairan / Multibyte_list_encondings.php
Last active June 14, 2018 14:33
Detect encoding of string using Multibyte snippet created to test Oracle strings #oracle
$text = "A strånge string to pass, maybe with søme ø, æ, å characters.";
foreach(mb_list_encodings() as $charset){
echo mb_convert_encoding($text, 'UTF-8', $charset)." : ".$charset."<br>";
}
@tallesairan
tallesairan / README.md
Last active March 25, 2024 22:06
check if the post exists by slug and post type #wp

Tips

very useful when you can have an attachment with the same slug as a post record_exists_by_slug You can check the post if it exists as an attachment you can change, this way it is practically impossible to duplicate a post

@tallesairan
tallesairan / WooCommerce.sql
Last active June 20, 2018 14:58
Delete all WooCommerce products, terms, postmeta and relationships #wp #wpdb #intermediary
-- Delete all WooCommerce products
DELETE FROM wpcl_term_relationships WHERE object_id IN (SELECT ID FROM wpcl_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wpcl_postmeta WHERE post_id IN (SELECT ID FROM wpcl_posts WHERE post_type IN ('product','product_variation'));
DELETE FROM wpcl_posts WHERE post_type IN ('product','product_variation');
-- Delete all WooCommerce terms
DELETE a,c FROM wpcl_terms AS a
LEFT JOIN wpcl_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wpcl_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_tag';
-- Delete All WooCommerce relationships
@tallesairan
tallesairan / order.sql
Created June 21, 2018 12:07
Get order items from database #woocommerce #db #mysql #wp
SELECT order_item_name,
order_id,meta.order_item_id meta_item,
meta.meta_key meta_key,
meta.meta_value meta_value
FROM `unf_woocommerce_order_items` items
LEFT JOIN unf_woocommerce_order_itemmeta meta ON meta.order_item_id = items.order_item_id
WHERE order_id = 458
@tallesairan
tallesairan / delete-all-woocommerce-products.php
Created August 15, 2018 17:27 — forked from mikaelz/delete-all-woocommerce-products.php
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')");