Skip to content

Instantly share code, notes, and snippets.

View trajche's full-sized avatar
🍕
Hungry

Trajche TJ Kralev trajche

🍕
Hungry
  • Helsinki, Finland
View GitHub Profile
@trajche
trajche / functions.php
Created March 2, 2014 12:32
Woocommerce: Add product out of stock badge
add_action('woocommerce_before_shop_loop_item_title','product_out_of_stock_badge');
function product_out_of_stock_badge() {
global $woocommerce, $product, $post;
$post_id = $post->ID;
$available_variations = $product->get_available_variations();
foreach ($available_variations as $variation) {
$isinstock = $variation[is_in_stock];
if ($isinstock === true) {
$i++;
}
@trajche
trajche / wp-one-liner
Created December 11, 2019 10:41
One liner for WordPress download and unpacking in the current directory.
curl -O https://wordpress.org/latest.zip && unzip latest.zip && rm latest.zip && mv wordpress/* ./ && rm -r wordpress/
@trajche
trajche / headerparser.php
Last active November 5, 2019 19:56
link rel parser for headers in shopify / github
function returnHeaderArray($linkHeader) {
$cleanArray = [];
if (strpos($linkHeader, ',') !== false) {
//Split into two or more elements by comma
$linkHeaderArr = explode(',', $linkHeader);
} else {
//Create array with one element
$linkHeaderArr[] = $linkHeader;
@trajche
trajche / delete-all-products.php
Last active July 2, 2019 09:35 — forked from mikaelz/delete-all-woocommerce-products.php
Remove all WooCommerce products from database via SQL
<?php
require dirname(__FILE__).'/wp-blog-header.php';
//Removing attributes (does not work for some reason, should read up on https://www.webhat.in/article/woocommerce-tutorial/how-product-attribute-are-stored-in-database/)
$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)");
//Removing products and product variations
@trajche
trajche / woocomerce_clean
Last active May 15, 2018 13:51 — forked from ScottDeLuzio/mysql_query
MySQL query remove Woocommerce sessions & transients
DELETE FROM wp_options WHERE option_name LIKE '_wc_session_%' OR option_name LIKE '_wc_session_expires_%';
DELETE FROM wp_options WHERE option_name LIKE '_transient_wc_%' OR option_name LIKE '_transient_timeout_wc_%';
@trajche
trajche / multiple-select-woocommerce.php
Created March 7, 2018 13:51
WooCommerce Product multiple select options
function woocommerce_wp_select_multiple( $field ) {
global $thepostid, $post, $woocommerce;
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
$field['value'] = isset( $field['value'] ) ? $field['value'] : ( get_post_meta( $thepostid, $field['id'], true ) ? get_post_meta( $thepostid, $field['id'], true ) : array() );
@trajche
trajche / countries.html
Created January 20, 2017 10:27
salesforce country list
<select id="con18country" name="con18country" tabindex="26">
<option value="">
--None--
</option>
<option value="AF">
Afghanistan
</option>
<option value="AX">
Aland Islands
</option>
@trajche
trajche / functions.php
Last active December 31, 2015 08:59
Remove WP Core Update Notifications
add_filter( 'pre_site_transient_update_core', create_function( '$a', "return null;" ) );
Installing new box for nginx-wordpress (ubuntu minimal):
Prepare server
------------------------------------
apt-get update
apt-get upgrade
apt-get dist-upgrade #upgrade distribution
apt-get install sudo dialog software-properties-common python-software-properties
apt-get install bsdutils #for percona
@trajche
trajche / sources.list
Created December 15, 2015 04:20
Adding Proxmox repository for Debian 8.2 Jessie
deb http://mirror.hetzner.de/debian/packages jessie main contrib non-free
deb http://http.debian.net/debian jessie main contrib non-free
deb http://http.debian.net/debian/ jessie-updates main contrib non-free
deb http://download.proxmox.com/debian jessie pve-no-subscription
deb http://security.debian.org/ jessie/updates main contrib non-free