I
I
IvanRu082020-03-27 13:54:09
Computer networks
IvanRu08, 2020-03-27 13:54:09

How to display products by Woocommerce SKU?

Hello. I write a shortcode like [products skus="BDS-15-800, BDS-20-800"]. You need to get an array of products by article. I do it like this:

function creazor_products_func( $atts ){
    $params = shortcode_atts( array( // в массиве укажите значения параметров по умолчанию
      'skus' => '', // параметр 1
    ), $atts );

    //раздлеяем строку в масси
    $skus_arr = explode( ',', $params['skus'] );
    foreach ( $skus_arr as &$arr ) $arr = trim( $arr );

    $args = array(
      'post_type' => 'product',
      'posts_per_page' => 4,
      'order'     => 'ASC',
      'meta_key' => '_sku',
      'meta_value' => $skus_arr
    );
    $products = new WP_Query( $args );
  }


One product is constantly displayed, although in theory it should be displayed exactly as much as passed in the shortcode parameters. If you enter these articles one by one, then everything works. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2019-09-08
@Zoominger

You should contact MTS technical support.

C
CityCat4, 2019-09-08
@CityCat4

- Dryukat MTS support - for example, you can go to their office and make a scandal :)
- Move away from MTS to a more sane Provo. (compared to them, even Dom.Sru is good)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question