Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use this snippet to prevent composites with component discounts from appearing as on-sale.
<?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: SomewhereWarm
* Author URI: https://somewherewarm.gr/
* Developer: Manos Psychogyiopoulos
*
* Requires at least: 4.1
* Tested up to: 5.3
*
* Copyright: © 2017-2020 SomewhereWarm SMPC (info@somewherewarm.gr).
* 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;
}
@brianjking

This comment has been minimized.

Copy link

@brianjking brianjking commented Sep 14, 2017

@franticpsyx Where do I create this file? Inside of the composite products folder in my WP install?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.