Skip to content

Instantly share code, notes, and snippets.

@stefaeva
stefaeva / WC_variable_products.php
Last active June 1, 2020 14:23
Woocommerce - show product variations without product parent
/* i need help to modify this snippet to show only the product variations without the product parent */
add_action( 'pre_get_posts', 'custom_remove_products_from_shop_page' );
function custom_remove_products_from_shop_page( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
$q->set( 'post__in', array(0) ); }
remove_action( 'pre_get_posts', 'custom_remove_products_from_shop_page' );
@stefaeva
stefaeva / functions.php
Created June 1, 2020 17:08 — forked from cagartner/functions.php
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;