• Dani

    (@danicasati)


    Hi.
    Is it possible to add a shortcode (like Woocommerce shortcodes included in code) in order to filter products by vendor?

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi,
    and thank you for writing in!

    Unfortunately this plugin version doesn’t include that shortcode; it’s available in the premium version only.
    You can find the shortcodes available in the premium version by following this link:
    https://docs.yithemes.com/yith-woocommerce-multi-vendor/premium-version-settings/shortcodes/
    The one you are searching for is yith_wcmv_vendor_products.

    Thread Starter Dani

    (@danicasati)

    Ok, but in case of use PREMIUM version, is it possible to detect vendor ID in single product page with a snippet? So, shortcode could be displayed only in certain products.

    Plugin Author YITHEMES

    (@yithemes)

    Hi Dani,
    yes, you can obtain the vendor ID in single product page, you need few lines of code.

    Thread Starter Dani

    (@danicasati)

    Did you publish this code in any documentation?
    Will it work with FREE version of the plugin?

    For example:
    – If user is display single product AND vendor ID is X, display a product selection.

    Plugin Author YITHEMES

    (@yithemes)

    Hi there,
    suppose you’re working inside a product template, you could use following code to obtain the vendor object.

    global $product;
    $vendor = yith_get_vendor( $product, 'product' );

    You could get the vendor name this way

    if( $vendor->is_valid() && $vendor->name === 'john' ){
        //make something
    }
    • This reply was modified 4 years, 4 months ago by YITHEMES.
    Thread Starter Dani

    (@danicasati)

    Thank you for the code.
    But it would be better to add a function in FUNCTIONS.PHP.

    Thread Starter Dani

    (@danicasati)

    Maybe could you send code for retrieve vendor ID, not name?
    I’m trying to use the code in function in order to display random products of the same vendor of viewed product but it doesn’t work.

    Thread Starter Dani

    (@danicasati)

    Current function:

    add_action('woocommerce_after_single_product', 'my_morevendorsproducts', 10);
    function my_morevendorsproducts() { 
        global $product;
        $vendor = yith_get_vendor( $product, 'product' );
        
        if( $vendor->is_valid() && $vendor->name === 'xyz' ) {
            echo "<h3>More products</h3>";
            echo do_shortcode( '[yith_wcmv_vendor_products vendor_id=x limit=4 columns=4 orderby=rand]' );
        }
    }
    Thread Starter Dani

    (@danicasati)

    If
    yith_wcmv_vendor_products
    shortcode is not available on FREE version, maybe I could use a Woocommerce shortcode to display some products from vendor’s categories.

    Plugin Author YITHEMES

    (@yithemes)

    Hi @danicasati

    you can’t use the [products] shortcode of WooCommerce in text editor because it’s not possible to use it with a custom taxonomy.

    The only solution is to use a snippet of code like this:

    $vendor = yith_get_vendor( $sc_args['vendor_id'], 'vendor' );
    ob_start();
    
    if ( $vendor->is_valid() ) {
        $products = $vendor->get_products();
        if ( ! empty( $products ) ) {
            $extra_args = '';
            foreach ( $sc_args as $sc_att => $sc_value ) {
                $extra_args .= sprintf( ' %s="%s"', $sc_att, $sc_value );
            }
    
            $shortcode = sprintf( '[products ids="%s"%s]', implode( ',', $products ), $extra_args );
    
            echo do_shortcode( $shortcode );
        }
    }
    
    echo  ob_get_clean();

    Try this solution and let use know, please.

    Lines:

    4: if ( $vendor->is_valid() ) {
    5: $products = $vendor->get_products();
    8: foreach ( $sc_args as $sc_att => $sc_value ) {

    Gets an error when pasting html in widgets, “Special characters must be escaped : [ > ]”

    Hi @yithemes

    After adding the above code in functions.php, the shortcode [products ids=”%s”%s] returns all products.

    Is there anything I should change?

    Plugin Author YITHEMES

    (@yithemes)

    Hi there,

    please, Could you print the variable $shortcode ? We need to understand how the shortcode are write in order to understand the cause of the issue.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Shortcode to filter by vendor’ is closed to new replies.