Show SKU instead of attribute name
-
I would like the dropdown box on product page to show only the SKU number instead of the attribute name for variable products. I added this snippet and got it to show BOTH SKU and attribute name but I only want the SKU to show.
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 );
What do I need to change in my coding for it to work like I want? Any help would be greatly appreciated!
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Show SKU instead of attribute name’ is closed to new replies.