Last active
August 29, 2015 14:21
-
-
Save JeroenSormani/777fbfa3a4f4ccf4a0dd to your computer and use it in GitHub Desktop.
Custom WAS subtotal match. Exclude virtual product amount in subtotal.
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 | |
remove_all_filters( 'was_match_condition_subtotal' ); | |
add_filter( 'was_match_condition_subtotal', 'new_was_match_condition_subtotal', 10, 3 ); | |
/** | |
* Custom subtotal matching. | |
* | |
* Match the subtotal amount without virtual products. | |
* | |
* @global object $woocommerce WooCommerce object. | |
* | |
* @param bool $match Current match value. | |
* @param string $operator Operator selected by the user in the condition row. | |
* @param mixed $value Value given by the user in the condition row. | |
* @return BOOL Matching result, TRUE if results match, otherwise FALSE. | |
*/ | |
function new_was_match_condition_subtotal( $match, $operator, $value ) { | |
if ( ! isset( WC()->cart ) ) return; | |
$subtotal = 0; | |
foreach( WC()->cart->get_cart() as $item ) : | |
if ( 'no' == $item['data']->virtual ) : | |
$subtotal += $item['line_total']; | |
endif; | |
endforeach; | |
if ( '==' == $operator ) : | |
$match = ( $subtotal == $value ); | |
elseif ( '!=' == $operator ) : | |
$match = ( $subtotal != $value ); | |
elseif ( '>=' == $operator ) : | |
$match = ( $subtotal >= $value ); | |
elseif ( '<=' == $operator ) : | |
$match = ( $subtotal <= $value ); | |
endif; | |
return $match; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment