Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Last active January 26, 2022 07:17
Show Gist options
  • Save pramodjodhani/eaa39f68dddf84f8a50ff01057c42fcd to your computer and use it in GitHub Desktop.
Save pramodjodhani/eaa39f68dddf84f8a50ff01057c42fcd to your computer and use it in GitHub Desktop.
WooCommerce: User parent product's description if child product's description is empty
<?php
/**
* Iconic SSV: use parent's description if child product's description is empty.
*
* @param string $description
* @param object $product
*
* @return string
*/
function iconic_ssv_modify_variation_description( $description, $product ) {
if ( ! $product->is_type( 'variation' ) || ! empty( $description ) ) {
return $description;
}
// get parent products description.
$parent_id = $product->get_parent_id();
$parent_product = wc_get_product( $parent_id );
if ( ! $parent_product ) {
return $description;
}
return $parent_product->get_description();
}
add_filter( 'woocommerce_product_variation_get_description', 'iconic_ssv_modify_variation_description', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment