/**
* Get product variation dimensions
* @param $product_id int product_id
*
* @return array product variation dimensions
*/
function wpp_get_product_variation_dimensions($product_id) {
$product = get_product( $product_id );
$out = array();
if ( $product->is_type( 'variable' ) ) {
$variations = $product->get_available_variations();
foreach ( $variations as $variable_array ) {
$variation = new WC_Product( $variable_array[ 'variation_id' ] );
$out[ 'variation_' . $variation->id ] = array(
'weight' => $variation->weight,
'length' => $variation->length,
'width' => $variation->width,
'height' => $variation->height
);
}
}
return $out;
}
использование
$tt = wpp_get_product_variation_dimensions(133821);
вернет
array( 2 ) {
[ "variation_133823" ]=>
array( 4 ) {
[ "weight" ]=>
string( 1 ) "3"
[ "length" ]=>
string( 3 ) "500"
[ "width" ]=>
string( 3 ) "700"
[ "height" ]=>
string( 3 ) "200"
}
[ "variation_133824" ]=>
array( 4 ) {
[ "weight" ]=>
string( 1 ) "2"
[ "length" ]=>
string( 3 ) "200"
[ "width" ]=>
string( 3 ) "270"
[ "height" ]=>
string( 3 ) "500"
}
}