Last active
July 4, 2023 20:09
-
-
Save yaovicoder/f4e87f795a1d368aa9dd4d8761028797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: WooCommerce Variable Product Variation Descriptions | |
* Description: Replaces the product short description with the descriptions of all visible and priced variations. | |
* Version: 1.0 | |
* Author: Yaovi Ametepe | |
* Released: July 4th, 2023 | |
*/ | |
/** | |
* Replaces the product short description with the descriptions of all visible and priced variations. | |
* | |
* @param string $short_description The original product short description. | |
* @return string The modified short description. | |
*/ | |
function replace_product_short_description_with_variation( $short_description ) { | |
global $product; | |
if ( is_product() && $product->is_type( 'variable' ) && $product->has_child() ) { | |
$variation_descriptions = array(); | |
foreach ( $product->get_available_variations() as $variation ) { | |
if ( $variation['variation_is_visible'] && $variation['display_price'] !== '' ) { | |
$variation_description = get_post_field( 'post_content', $variation['variation_id'] ); | |
$variation_descriptions[] = $variation_description; | |
} | |
} | |
if ( ! empty( $variation_descriptions ) ) { | |
$short_description = implode( '', $variation_descriptions ); | |
} | |
} | |
return $short_description; | |
} | |
add_filter( 'woocommerce_short_description', 'replace_product_short_description_with_variation' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment