Skip to content

Instantly share code, notes, and snippets.

@manospsyx
Last active February 29, 2020 20:34
Show Gist options
  • Save manospsyx/ea1bbed59a27d763907634e0e46b8986 to your computer and use it in GitHub Desktop.
Save manospsyx/ea1bbed59a27d763907634e0e46b8986 to your computer and use it in GitHub Desktop.
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
Copy link

@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