admin管理员组文章数量:1277274
As a result of my research, I can bring similar sku ones no matter which product I enter, but I encountered a problem, the sku code of the product I entered changes.
E.g:
1- ) 36.214.03
2- ) 36.214.19
3- ) 36.214.17
This is how sku values similar to the product I entered are returned. I keep the sku code of each product at the bottom. The Sku code of the product I entered should be "36,214,19" but it always prints the last Sku code as "36,214,17", how can I avoid this?
In short, what can I do so that the product's own sku code does not change?
Following my code: functions.php
function wc_get_product_skus( $sku_excerpt ) {
global $wpdb;
// Get all product Ids and skus (standard objects) from a sku excerpt
return $wpdb->get_results( $wpdb->prepare( "
SELECT p.ID as id, pm.meta_value as sku
FROM {$wpdb->prefix}posts p
INNER JOIN {$wpdb->prefix}postmeta pm
ON p.ID = pm.post_id
WHERE p.post_type = 'product'
AND p.post_status = 'publish'
AND pm.meta_key = '_sku'
AND pm.meta_value LIKE '%s'
", '%'.$sku_excerpt.'%' ) );
}
single-product.php
$results = wc_get_product_skus('36.214.');
// Loop through results
foreach ( $results as $result ) {
$product_id = $result->id;
$product_sku = $result->sku;
// Get the WC_Product Object (if needed)
$product = wc_get_product( $product_id );
// Testing output
echo 'Sku : '.$product_sku.'<br>';
}
Thanks in advance
本文标签: phpGet WooCommerce products with similar SKU
版权声明:本文标题:php - Get WooCommerce products with similar SKU 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741259125a2367264.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论