Skip to content

Instantly share code, notes, and snippets.

@fuyuko
fuyuko / functions.php
Last active July 21, 2023 13:06
Cheatsheet - WooCommerce Customization in functions.php
//Add a stylesheet after default style.css
wp_enqueue_style( 'my-css', get_template_directory_uri() . 'my-css.css', array('themename-style'));
//WooCommerce - Sort products by SKU
add_filter('woocommerce_get_catalog_ordering_args', 'custom_woocommerce_catalog_orderby');
function custom_woocommerce_catalog_orderby( $args ) {
$args['meta_key'] = '_sku';
$args['orderby'] = 'meta_value';
$args['order'] = 'asc';
return $args;
@fuyuko
fuyuko / plugin-name.php
Last active August 29, 2015 14:22
WordPress Plugin Development Template Files
<?php
/*
Plugin Name: Plugin Name
Plugin URI: https://github.com/fuyuko/plugin-repository
Description: Plugin description
Author: Fuyuko Gratton
Version: 0.1
Author URI: http://fuyuko.net/
*/
@fuyuko
fuyuko / woocommerce_locate_template.php
Last active August 29, 2015 14:22
A function to allow woocommerce to search woocommerce template in an external plugin
/**
* The normal WooCommerce template loader searches the following locations in order, until a match is found:
* 1. your theme / template path / template name
* 2. your theme / template name
* 3. default path / template name
*
* The new order of search will be:
* 1. your theme / template path / template name
* 2. your theme / template name
* 3. your plugin / woocommerce / template name
@fuyuko
fuyuko / wc_get_template_part
Created June 11, 2015 15:18
a function to allow woocommerce to search woocommerce template part in an external plugin.
/**
* FUNCTION OVERWRITE - wc_get_template_part (return template part overwritten in this plugin)
*/
add_filter('wc_get_template_part', 'myplugin_woocommerce_get_template_part', 10, 3);
function myplugin_woocommerce_get_template_part($template, $slug, $name){
$plugin_path = myplugin_plugin_path() . '/woocommerce/';
if(file_exists( $plugin_path . $slug . "-" . $name . ".php")){
$template = $plugin_path . $slug . "-" . $name . ".php";
@fuyuko
fuyuko / example.scss
Created July 13, 2015 17:19
SCSS Examples
/*-----------------------------------------------
Body - All
-----------------------------------------------*/
/*headings*/
@for $i from 1 through 6 {
h#{$i}{
font-family: Bitter, Arial, sans-serif;
color: rgb(107,57,8);
@fuyuko
fuyuko / woocommerce-weightcheck-with-quoteproduct.sql
Last active August 29, 2015 14:26
Query the woocommerce published products (both base products and variations) that have 0 or no weight assigned.
SELECT weight_info.post_id, weight_info.meta_key, weight_info.meta_value, wp_posts.post_title, quote_info.meta_key, quote_info.meta_value, wp_posts.post_status
FROM wordpress_cappels.wp_postmeta as weight_info
LEFT JOIN wordpress_cappels.wp_posts ON weight_info.post_id = wp_posts.ID
LEFT JOIN wordpress_cappels.wp_postmeta as quote_info ON quote_info.post_id = wp_posts.ID
where
weight_info.meta_key like '_weight' and
quote_info.meta_key like 'quote_product_checkbox' and
(weight_info.meta_value like '0' or weight_info.meta_value like '') and
(quote_info.meta_value like 'no' or quote_info.meta_value like '') and
wp_posts.post_status like 'publish' ;
@fuyuko
fuyuko / content-product_cat.php
Created August 19, 2015 15:09
WooCommerce Subcategory Content Template Overwrite - This template shows, subcategory's title, thumbnail, description, and its subcategries' links (and their subcategories links) Example Site: http://loadhook.wp3.cazbah.us/product-category/electric-chain-hoists/
<?php
/**
* The template for displaying product category thumbnails within loops.
*
* Override this template by copying it to yourtheme/woocommerce/content-product_cat.php
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.4.0
*/