This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_shortcode( 'header_cart', 'header_cart' ); | |
| function header_cart() { | |
| if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
| ob_start(); | |
| $cart_count = WC()->cart->get_cart_contents_count(); | |
| $cart_total = WC()->cart->get_cart_total(); | |
| $cart_url = wc_get_cart_url(); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // This example switches Shipping & Order Total rows | |
| add_filter( 'woocommerce_get_order_item_totals', 'reordering_order_item_totals', 10, 3 ); | |
| function reordering_order_item_totals( $total_rows, $order, $tax_display ){ | |
| // 1. saving the values of items totals to be reordered | |
| $shipping = $total_rows['shipping']; | |
| $order_total = $total_rows['order_total']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // GET CATEGORY OBJECT | |
| $categoryObject = get_queried_object(); | |
| // GET CATEGORY ID | |
| $categoryID = get_queried_object_id(); | |
| // GET CATEGORY ID FROM NAME | |
| $categoryID = get_cat_ID( $categoryName ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function get_product_categories() { | |
| // Parameters available here: https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#parameters | |
| $args = array( | |
| 'taxonomy' => 'product_cat', | |
| 'child_of' => 5, // Get child terms of category with ID 5 | |
| 'parent' => 5, // Get direct-child terms of category with ID 5 | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'get_terms', 'get_custom_category_terms', 10, 3 ); | |
| function get_custom_category_terms( $terms, $taxonomies, $args ) { | |
| $new_terms = array(); | |
| $hide_category = array( 217 ); // Ids of the category you don't want to display on the shop page | |
| if ( in_array( 'product_cat', $taxonomies ) && !is_admin() && is_shop() ) { | |
| foreach ( $terms as $key => $term ) { | |
| if ( ! in_array( $term->term_id, $hide_category ) ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' ); | |
| function custom_pre_get_posts_query( $q ) { | |
| $tax_query = (array) $q->get( 'tax_query' ); | |
| $tax_query[] = array( | |
| 'taxonomy' => 'product_cat', | |
| 'field' => 'slug', | |
| 'terms' => array( 'category'), // replace with your category slug |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' ); | |
| function custom_woocommerce_get_catalog_ordering_args( $args ) { | |
| $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); | |
| if ( 'date' == $orderby_value ) { // Orderby values are date, menu_order, popularity, rating, date, price, price-desc | |
| $args['order'] = 'asc'; | |
| } | |
| return $args; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // orderby values are date, menu_order, popularity, rating, date, price, price-desc | |
| add_filter( 'woocommerce_default_catalog_orderby', 'custom_default_catalog_orderby' ); | |
| function custom_default_catalog_orderby() { | |
| if ( is_product_category( array( 'category-1-slug', 'category-2-slug' ) ) ) { // Replace with your category slugs | |
| return 'menu_order'; | |
| } else { | |
| return 'date'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // orderby values are date, menu_order, popularity, rating, date, price, price-desc | |
| add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby', 20 ); | |
| function custom_woocommerce_catalog_orderby( $orderby ) { | |
| unset($orderby["price"]); // Remove price option | |
| return $orderby; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // SETS NUMBER OF PRODUCTS DISPLAYED PER PAGE | |
| add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 9999 ); | |
| function new_loop_shop_per_page( $cols ) { | |
| $cols = 30; | |
| return $cols; | |
| } | |