Have get_product_from_item only return variable product if it exists, and show on the order item row if the variation no longer exists.
Fixes #5536
This commit is contained in:
parent
e28b868000
commit
101254a6a3
|
@ -12,8 +12,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
echo '<strong>' . __( 'Product ID:', 'woocommerce' ) . '</strong> ' . absint( $item['product_id'] );
|
||||
|
||||
if ( $item['variation_id'] ) {
|
||||
if ( $item['variation_id'] && 'product_variation' === get_post_type( $item['variation_id'] ) ) {
|
||||
echo '<br/><strong>' . __( 'Variation ID:', 'woocommerce' ) . '</strong> ' . absint( $item['variation_id'] );
|
||||
} elseif ( $item['variation_id'] ) {
|
||||
echo '<br/><strong>' . __( 'Variation ID:', 'woocommerce' ) . '</strong> ' . absint( $item['variation_id'] ) . ' (' . __( 'No longer exists', 'woocommerce' ) . ')';
|
||||
}
|
||||
|
||||
if ( $_product && $_product->get_sku() ) {
|
||||
|
|
|
@ -1281,8 +1281,11 @@ class WC_Order {
|
|||
* @return WC_Product
|
||||
*/
|
||||
public function get_product_from_item( $item ) {
|
||||
$_product = get_product( ! empty( $item['variation_id'] ) ? $item['variation_id'] : $item['product_id'] );
|
||||
|
||||
if ( ! empty( $item['variation_id'] ) && 'product_variation' === get_post_type( $item['variation_id'] ) ) {
|
||||
$_product = get_product( $item['variation_id'] );
|
||||
} else {
|
||||
$_product = get_product( $item['product_id'] );
|
||||
}
|
||||
return apply_filters( 'woocommerce_get_product_from_item', $_product, $item, $this );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue