Skip to content

Instantly share code, notes, and snippets.

@attilabacso
attilabacso / Get Woo Product category ID
Last active August 29, 2015 14:24
Get woocommerce product category ID from product single
//Get product term_id
$category = get_the_terms(get_the_ID(),'product_cat');
$p_term_id=key($category);
$p_term_obj=get_term_by('id', $p_term_id, 'product_cat');
$p_term_tree = get_ancestors($p_term_id, 'product_cat');
if(!$p_term_tree) {
//this product category is a top level category
$p_top_term=$p_term_id;
} else {
$p_top_term=end($p_term_tree);
<?php
function xmas_closed(){
global $woocommerce;
date_default_timezone_set('Europe/Stockholm');
$current_date=date("m-d");
$open_from="14:00";
$open_till="22:00";
$current_time=date("H:i");
add_filter('body_class','browser_body_class');
function browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
<?php
//Set minimum order amount
function minimum_order_func(){
global $woocommerce;
if (is_checkout()){
$minorder = 1500;
// If the cart is empty and the order_total less than $minorder (1500)
<?php
/* Custom woocommerce loop and add to isotope container */
// Display woo products order by price
$args=array(
'post_type' => 'product',
'post_status' => 'publish',
'orderby' => 'meta_value_num',
'meta_key' => '_price',
// Put functions.php
add_filter('give_format_amount', 'give_remove_thousands_seperator');
function give_remove_thousands_seperator($amount, $decimals = true) {
$thousands_sep = '';
$decimal_sep = give_get_option( 'decimal_separator', '.' );
if ( empty( $amount ) ) {
@attilabacso
attilabacso / jquery_phone_number_restriction.js
Last active June 20, 2017 16:51
Jquery Phone number restriction
// Phone number restriction for input_10_4 field
// Start with + character
$('#input_10_4').val('+');
$('#input_10_4').attr('data-initial', '+');
// Cannot delete the + character
$("#input_10_4").on("keyup", function() {
/*
This code should be include in functions.php
*/
/* Custom 'super-editor' user role (ID, not label) */
// This is the name of custom user role, you can change to anything, but this role should be exists
// You can add any custom user role eg. with Vladimir Garagulya User Role Editor plugin
if (current_user_can( 'super-editor' )) {
# Delete all WooCommerce orders, order_meta and order post_meta datas
DELETE FROM wp_woocommerce_order_itemmeta;
DELETE FROM wp_woocommerce_order_items;
DELETE FROM wp_comments WHERE comment_type = 'order_note';
DELETE FROM wp_postmeta WHERE post_id IN ( SELECT ID FROM wp_posts WHERE post_type = 'shop_order' );
DELETE FROM wp_posts WHERE post_type = 'shop_order';
// SELECT ON CHANGE VALUES FETCHING TO PHP
document.querySelectorAll(`select.collect`).forEach(dropdown =>
dropdown.addEventListener(`change`, (e) => {
// GET VALUES
let value = e.target.value;
let text = dropdown.options[dropdown.selectedIndex].text;
let price = dropdown.options[dropdown.selectedIndex].getAttribute(`attr-price`);