1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57:
<?php
namespace VSP\Core\Traits\WC_Compatibility;
defined( 'ABSPATH' ) || exit;
use WC_Product;
trait Product {
public static function get_product_id( $product ) {
if ( is_numeric( $product ) ) {
return $product;
}
if ( $product instanceof WC_Product && method_exists( $product, 'get_id' ) ) {
return $product->get_id();
}
if ( static::compare( '3.0', '<' ) && $product instanceof WC_Product && isset( $product->ID ) ) {
return $product->ID;
}
return false;
}
public static function get_product_type( $product ) {
if ( is_numeric( $product ) ) {
$product = wc_get_product( $product );
}
if ( ! $product instanceof WC_Product ) {
return false;
}
return ( static::compare( '3.0', '>=' ) ) ? $product->get_type() : $product->product_type;
}
}