Support » Theme: Sinatra » Show SKU instead of attribute name

  • Resolved ettermanenterprises

    (@ettermanenterprises)


    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?

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.