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 | |
| 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( '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 | |
| 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 | |
| // 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 | |
| // 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 | |
| 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 | |
| // Shortcode example: [display_subcats id="55"]. Replace 55 with your parent category ID | |
| add_shortcode('display_subcats', 'display_subcats'); | |
| function display_subcats( $atts, $content = null ) { | |
| $atts = shortcode_atts( | |
| array( | |
| 'id' => '' |
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 has_woocommerce_subscription($the_user_id, $the_product_id, $the_status) { | |
| if ( empty($the_user_id) ) { | |
| $the_user_id = get_current_user_id(); | |
| } | |
| if (wcs_user_has_subscription( $the_user_id, $the_product_id, $the_status)) { | |
| return true; | |
| } | |
| } |
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_account_downloads_column_download-product', 'custom_account_downloads_product_name' ); | |
| function custom_account_downloads_product_name( $download ){ | |
| echo esc_html( $download['product_name'] ); | |
| } | |
| ?> |