Last active
November 17, 2021 14:29
-
-
Save somewherewarm-snippets/a8fe98be1885025192b2ebdebe8c7b4b 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 Composite Products - Sale Status Tweak | |
* Plugin URI: https://woocommerce.com/products/composite-products/ | |
* Description: Prevents Composite Products with component discounts from appearing as on-sale. | |
* Version: 1.0 | |
* Author: WooCommerce | |
* Author URI: https://woocommerce.com/ | |
* Developer: Manos Psychogyiopoulos | |
* | |
* Requires at least: 4.1 | |
* Tested up to: 5.3 | |
* | |
* Copyright: © 2021 Automattic. | |
* License: GNU General Public License v3.0 | |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
add_filter( 'woocommerce_product_is_on_sale', 'wc_cp_component_discounts_sale_status', 10, 2 ); | |
function wc_cp_component_discounts_sale_status( $on_sale, $product ) { | |
if ( $on_sale && 'composite' === $product->get_type() && $product->contains( 'priced_individually' ) ) { | |
$product = new WC_Product_Simple( $product->get_id() ); | |
$on_sale = $product->is_on_sale(); | |
} | |
return $on_sale; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, thank you for testing.
I can see that the badge was remove, but the price is the same. We want that the sale products when they are in composite the price to buy will be the regular price, not sale price. Sale price just if you are buying just this product. For example. Could you help us?
Thanks.