1 回答

TA贡献2037条经验 获得超6个赞
function display_price_in_variation_option_name( $term ) {
global $wpdb, $product;
if( isset( $product ) ) {
$query = sprintf( "SELECT postmeta.post_id AS product_id
FROM {$wpdb->prefix}postmeta postmeta
LEFT JOIN {$wpdb->prefix}posts products ON ( products.id = postmeta.post_id )
WHERE postmeta.meta_key LIKE 'attribute_%%'
AND postmeta.meta_value = '%s'
AND products.post_parent = %d", $term, $product->get_id() );
$results = $wpdb->get_results( $query );
foreach ($results as $key => $result) {
$variation_id = $result->product_id;
}
$variation_sku = get_post_meta( $variation_id , '_sku', TRUE );
$term = $term . ' ('. $variation_sku .')';
}
return $term;
}
add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name', 10, 1 );
- 1 回答
- 0 关注
- 71 浏览
添加回答
举报