| Carat | 0.54 |
|---|---|
| Clarity | VS2 |
| Color | S-T |
| Grading Report | GIA |
| Item Type | Loose Diamond |
| Shape | |
| Type of Diamond | Natural Diamond |
function diamocycle_product_filter() { ob_start(); $current_url = ( is_shop() ) ? get_permalink( wc_get_page_id( 'shop' ) ) : get_permalink(); echo '
'; // Enhanced Style echo ''; return ob_get_clean(); } add_shortcode( 'diamocycle_filter', 'diamocycle_product_filter' ); // 3. Apply Filters to Query (pre_get_posts) function diamocycle_filter_query( $query ) { if ( is_admin() || ! $query->is_main_query() ) return; if ( ! ( is_shop() || is_product_taxonomy() || is_page('market-place-2') ) ) return; $tax_query = $query->get('tax_query') ?: array(); // Category filters foreach ( ['diamond-type','item-type','diamond-shape'] as $param ) { if ( ! empty( $_GET[$param] ) ) { $tax_query[] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => sanitize_text_field( $_GET[$param] ), ); } } // Minimum Carat (attribute) if ( ! empty( $_GET['carat'] ) ) { $min = floatval( $_GET['carat'] ); $terms = get_terms( array( 'taxonomy' => 'pa_carat', 'hide_empty' => true ) ); $slugs = array(); foreach ( $terms as $term ) { if ( floatval( $term->name ) >= $min ) $slugs[] = $term->slug; } if ( $slugs ) { $tax_query[] = array( 'taxonomy' => 'pa_carat', 'field' => 'slug', 'terms' => $slugs, 'operator' => 'IN', ); } } // Attribute filters (clarity, color, ring_size) foreach ( ['clarity','color','ring_size'] as $attr ) { if ( ! empty( $_GET[$attr] ) ) { $tax_query[] = array( 'taxonomy' => 'pa_' . $attr, 'field' => 'slug', 'terms' => sanitize_text_field( $_GET[$attr] ), ); } } if ( count($tax_query) > 1 ) $tax_query['relation'] = 'AND'; if ( ! empty( $tax_query ) ) $query->set( 'tax_query', $tax_query ); } add_action( 'pre_get_posts', 'diamocycle_filter_query', 100 ); }| Carat | 0.54 |
|---|---|
| Clarity | VS2 |
| Color | S-T |
| Grading Report | GIA |
| Item Type | Loose Diamond |
| Shape | |
| Type of Diamond | Natural Diamond |