PHP Developers Network
http://forums.devnetwork.net/

How do we build a Shortcode for Wordpress?
http://forums.devnetwork.net/viewtopic.php?f=1&t=147880
Page 1 of 1

Author:  simonmlewis [ Tue Mar 26, 2019 6:17 am ]
Post subject:  How do we build a Shortcode for Wordpress?

Syntax: [ Download ] [ Hide ]
// Note: products shortcode docs https://docs.woocommerce.com/document/w ... #section-6
// In order for the snippet to work, you must add the parameter orderby = "stock" to the shortcode
// You can add more parameters to it of course e.g. limit, paginate, etc. It's all in the docs
 
add_filter('woocommerce_shortcode_products_query', 'bbloomer_sort_by_stock_status_shortcode', 999, 3);
function bbloomer_sort_by_stock_status_shortcode( $args, $atts, $type ) {
    if ( $atts['orderby'] == "stock" ) {
        $args['orderby']  = array( 'meta_value' => 'ASC' );
        $args['meta_key'] = array('_stock_status';
    }
    return $args;
}

This is a function we found to add 'stock' to the Shortcode "orderby".
Trouble is, we want it to sort by Stock then by Title.

So the page ends up showing it in Alpha order, but with all the 'in stock' coming first.

Author:  Vegan [ Tue Apr 02, 2019 12:02 am ]
Post subject:  Re: How do we build a Shortcode for Wordpress?

you might want to talk to the people with woocommerce who might be able to help with their code base

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/