Answer the question
In order to leave comments, you need to log in
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 );
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question