Fixed expected result from WC_Product::get_post_data for variations

This commit is contained in:
Claudio Sanches 2016-11-21 20:10:35 -02:00
parent 351f983e97
commit 4f7290daa0
1 changed files with 10 additions and 10 deletions

View File

@ -449,7 +449,15 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
*/
public function get_post_data() {
_deprecated_function( 'WC_Product::get_post_data', '2.7', 'get_post' );
return get_post( $this->get_id() );
// In order to keep backwards compatibility it's required to use the parent data for variations.
if ( $this->is_type( 'variation' ) ) {
$post_data = get_post( $this->get_parent_id() );
} else {
$post_data = get_post( $this->get_id() );
}
return $post_data;
}
/**
@ -461,15 +469,7 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
public function get_title() {
_deprecated_function( 'WC_Product::get_title', '2.7', 'WC_Product::get_name' );
// In order to keep backwards compatibility it's required to use the parent title for variations.
if ( $this->is_type( 'variation' ) ) {
$parent = get_post( $this->get_parent_id() );
$title = $parent ? $parent->post_title : '';
} else {
$title = $this->get_post_data() ? $this->get_post_data()->post_title : '';
}
return apply_filters( 'woocommerce_product_title', $title, $this );
return apply_filters( 'woocommerce_product_title', $this->get_post_data() ? $this->get_post_data()->post_title : '', $this );
}
/**