|
12 | 12 | exit; // Exit if accessed directly
|
13 | 13 | }
|
14 | 14 |
|
15 |
| -global $product; |
| 15 | +global $product, $woocommerce; |
16 | 16 |
|
17 | 17 | if ( ! $product->is_purchasable() ) {
|
18 | 18 | return;
|
19 | 19 | }
|
20 | 20 |
|
21 |
| -echo wc_get_stock_html( $product ); |
| 21 | +if ( version_compare( $woocommerce->version, 3.0, '>' ) ) { |
| 22 | + echo wc_get_stock_html( $product ); |
| 23 | +} else { |
| 24 | + // Availability. |
| 25 | + $availability = $product->get_availability(); |
| 26 | + $availability_html = empty( $availability['availability'] ) ? '' : '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>'; |
| 27 | + echo apply_filters( 'woocommerce_stock_html', $availability_html, $availability['availability'], $product ); |
| 28 | +} |
22 | 29 | ?>
|
23 | 30 |
|
24 | 31 | <?php if ( $product->is_in_stock() ) : ?>
|
|
31 | 38 | <?php do_action( 'woocommerce_before_add_to_cart_quantity' ); ?>
|
32 | 39 |
|
33 | 40 | <?php
|
34 |
| - woocommerce_quantity_input( array( |
35 |
| - 'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ), |
36 |
| - 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ), |
37 |
| - 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(), |
38 |
| - ) ); |
| 41 | + if ( version_compare( $woocommerce->version, 3.0, '>' ) ) { |
| 42 | + woocommerce_quantity_input( array( |
| 43 | + 'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ), |
| 44 | + 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ), |
| 45 | + 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(), |
| 46 | + ) ); |
| 47 | + } else { |
| 48 | + if ( ! $product->is_sold_individually() ) { |
| 49 | + woocommerce_quantity_input( array( |
| 50 | + 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ), |
| 51 | + 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ), |
| 52 | + 'input_value' => ( isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1 ) |
| 53 | + ) ); |
| 54 | + } |
| 55 | + } |
39 | 56 | ?>
|
40 | 57 |
|
41 | 58 | <?php do_action( 'woocommerce_after_add_to_cart_quantity' ); ?>
|
|
0 commit comments