Answer the question
In order to leave comments, you need to log in
woocommerce data output?
Guys, such a question. How to display these data of a variable product in an arbitrary place?
Answer the question
In order to leave comments, you need to log in
/**
* 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;
}
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"
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question