woocommerce variation option name on frontend

Solutions on MaxInterview for woocommerce variation option name on frontend by the best coders in the world

showing results for - "woocommerce variation option name on frontend"
Jakob
07 Jun 2017
1add_filter( 'woocommerce_variation_option_name','display_price_in_variation_option_name');
2
3function display_price_in_variation_option_name( $term ) {
4    global $product;
5
6    if ( empty( $term ) ) {
7        return $term;
8    }
9    if ( empty( $product->id ) ) {
10        return $term;
11    }
12
13    $variation_id = $product->get_children();
14
15    foreach ( $variation_id as $id ) {
16        $_product       = new WC_Product_Variation( $id );
17        $variation_data = $_product->get_variation_attributes();
18
19        foreach ( $variation_data as $key => $data ) {
20
21            if ( $data == $term ) {
22                $html  = wp_kses( woocommerce_price( $_product->get_price() ), array() );
23                $html .= ' - ' . $term;
24                $html .= ( $_product->get_stock_quantity() ) ? ' - ' . $_product->get_stock_quantity() : '';
25                return $html;
26            }
27        }
28    }
29
30    return $term;
31
32}
33
Levy
07 Oct 2017
1add_filter( 'woocommerce_variation_option_name','display_price_in_variation_option_name');
2
3function display_price_in_variation_option_name( $term ) {
4global $product;
5
6if ( empty( $term ) ) {
7    return $term;
8}
9if ( empty( $product->id ) ) {
10    return $term;
11}
12
13$variation_id = $product->get_children();
14
15
16foreach ( $variation_id as $id ) {
17    $_product       = new WC_Product_Variation( $id );
18    $variation_data = $_product->get_variation_attributes();
19    $stock_status = $_product->get_stock_status();
20    $stock_status = str_replace( array('instock','outofstock','onbackorder'), array('In Stock','Out of Stock','Please allow a few extra days for delivery'), $stock_status );
21
22    foreach ( $variation_data as $key => $data ) {
23
24        if ( $data == $term ) {
25            $html  = wp_kses( woocommerce_price( $_product->get_price() ), array() );
26            $html .= ' - ' . $term;
27            $html .= ( $stock_status ) ? ' - ' . $stock_status : '';
28            return $html;
29        }
30    }
31}
32
33return $term;
34
35}
36