Home Forums WoodMart support forum Query parameter

Query parameter

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #555011

    Jonatas
    Participant

    I would like to know how I can have a query parameter for “Product Tags” New (New). For example, I have a query parameter https://davyjones.com.br/?s=Gola%20O&post_type=product, which filters the products entered in the “Gola O” category.

    #555167

    Aizaz Imtiaz Awan
    Keymaster
    Xtemos team

    Hello,

    Sorry to say but we didn’t seem to understand your concern properly. Could you please elaborate on your concern more with some useful Screenshots so that we can better understand and assist you accordingly or share some examples of what you actually want.

    Best Regards.

    #555230

    Jonatas
    Participant

    I’ll explain better, I would like to know if the theme offers support so I can filter
    only the products that have the “new” label in their image, but I would like to know if it is possible to get this information through url parameters, as I had mentioned in the previous message this url https://davyjones.com.br/?s= Gola%20O&post_type=product can only filter products from the “Gola O” category using the URL parameter ?s=Gola%20O&post_type=product, I sent the images so you can understand better.

    Attachments:
    You must be logged in to view attached files.
    #555295

    Aizaz Imtiaz Awan
    Keymaster
    Xtemos team

    Hello,

    Define the code below in the functions.php file in your child theme. You can sort the new label in the sorting option of the shop page.
    https://ibb.co/2g7k4QX

    function skyverge_add_postmeta_ordering_args( $sort_args ) {
    
        $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
        switch( $orderby_value ) {
    
            // Name your sortby key whatever you’d like; must correspond to the $sortby in the next function
            case 'new_label':
                $sort_args['orderby'] = 'meta_value';
                // Sort by meta_value because we’re using alphabetic sorting
                $sort_args['order'] = 'asc';
                $sort_args['meta_key'] = '_woodmart_new_label';
                // use the meta key you’ve set for your custom field, i.e., something like “location” or “_wholesale_price”
                break;
        }
    
        return $sort_args;
    }
    add_filter( 'woocommerce_get_catalog_ordering_args', 'skyverge_add_postmeta_ordering_args' );
    // Add these new sorting arguments to the sortby options on the frontend
    function skyverge_add_new_postmeta_orderby( $sortby ) {
    
        // Adjust the text as desired
        $sortby['new_label'] = __( 'New Label', 'woocommerce' );
    
        return $sortby;
    }
    add_filter( 'woocommerce_default_catalog_orderby_options', 'skyverge_add_new_postmeta_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'skyverge_add_new_postmeta_orderby' );

    Best Regards.

    #555304

    Jonatas
    Participant

    I inserted your code but it is displaying only the parent products, as my products are variables and I use the WooCommerce Single Variations plugin, so I need this code to display only the product variations instead of showing only the parent products.

    #555354

    Aizaz Imtiaz Awan
    Keymaster
    Xtemos team

    Hello,

    Please try to remove the precious code and add the code below in the functions.php file in your child theme.

    function skyverge_add_postmeta_ordering_args( $sort_args ) {
        $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
        switch( $orderby_value ) {
            case 'new_label':
                $sort_args['orderby'] = 'meta_value';
                $sort_args['order'] = 'asc';
                $sort_args['meta_key'] = '_woodmart_new_label';
                $sort_args['orderby'] = 'meta_value_num';
                // Adjust the meta key to match the one used for product variations
                $sort_args['meta_query'] = array(
                    array(
                        'key' => '_variation_id', // Use _variation_id to target product variations
                        'compare' => 'EXISTS', // Ensure that variations exist
                    )
                );
                break;
        }
        return $sort_args;
    }
    add_filter( 'woocommerce_get_catalog_ordering_args', 'skyverge_add_postmeta_ordering_args' );
    
    function skyverge_add_new_postmeta_orderby( $sortby ) {
        $sortby['new_label'] = __( 'New Label', 'woocommerce' );
        return $sortby;
    }
    add_filter( 'woocommerce_default_catalog_orderby_options', 'skyverge_add_new_postmeta_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'skyverge_add_new_postmeta_orderby' );

    Best Regards.

    #555791

    Jonatas
    Participant

    Unfortunately this code didn’t work, it has the same behavior as the previous code

    #556020

    Aizaz Imtiaz Awan
    Keymaster
    Xtemos team

    Hello,

    Sorry but there is no option in Theme Settings available for that. It requires customizations and this is beyond our limitations and support policy.

    Try to find a plugin for this purpose. We have not tested such kinds of plugins, so we don’t have any detailed suggestions.

    Best Regards.

Viewing 8 posts - 1 through 8 (of 8 total)