• Hi,

    I want to exclude from free shipping the products that are on sale. I didn’t find a condition like that. Is that possible?
    I know I can set a category ‘sales’ and exclude that from free shipping but I think it will be better to have a condition like that.

    Thanks

    • This topic was modified 8 years, 6 months ago by Apostolis.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Jeroen Sormani

    (@sormano)

    Hi,

    There isn’t a condition based on whether a product in in sale. If you really need it you could extend the plugin to add your own custom condition.

    Aside from that, how did you have in mind things will work? Note that the Advanced Free Shipping plugin only allows you to setup free shipping for the entire package, so I’m not sure if you only wanted to exclude the sale items or when there are sale items in the cart.

    Have a great weekend!
    Jeroen Sormani

    Thread Starter Apostolis

    (@apokyro)

    Hi Jeroen,

    My condition goes like that: If you have at least one product on sale in cart don’t allow free shipping for all items in the cart. I think is pretty simple as condition.
    I will try to find a way to extend the plugin. I haven’t do something like that in the past.

    Thanks for your reply!
    Apostolis

    • This reply was modified 8 years, 6 months ago by Apostolis.
    Plugin Author Jeroen Sormani

    (@sormano)

    Hi Apostolis,

    Gotcha, a condition like that is indeed possible and not too hard.

    I wrote this doc about extending my other plugin that is very similar to this: https://docs.shopplugins.com/article/41-developer-adding-a-custom-condition

    You’d need to modify the hooks on that code (change the prefix to ‘wafs’), but other then that its a good example.

    Hope that helps ??

    Cheers,
    Jeroen

    Thread Starter Apostolis

    (@apokyro)

    Hi Jeroen, it’s been a while :).

    The link that you have provide it helped me a lot.
    I have almost done except one thing.

    My match condition it doesn’t hooks on front. I have written it in my functions.php (I use child theme) but it doesn’t seems to work.
    I tried to replace a condition of yours (subtotal) at class-wafs-match-conditions.php and from there it works.

    Can you help me? I don’t want to mess your great plugin :). You can find my code below.

    Thanks in advance

    
    // this function works ok
    function wafs_conditions_ex_offers_sub( $conditions ) {
    
    	// 'General', 'User Details', 'Cart' are default groups, you can also use something custom
    	$conditions['General']['offers'] = __( 'Subtotal ex. offers', 'woocommerce-advanced-shipping' );
    	return $conditions;
    }
    add_filter( 'wafs_conditions', 'wafs_conditions_ex_offers_sub', 10, 1 );
    
    // this function works ok
    function wafs_values_ex_offers_sub( $values, $condition ) {
    	switch ( $condition ) {
    		case 'offers':
    			$values['field'] = 'text';
    			$values['placeholder'] 	= 'add a price';
    
    			break;
    	}
    	return $values;
    }
    add_filter( 'wafs_values', 'wafs_values_ex_offers_sub', 10, 2 );
    
    // here is the problem
    function wafs_match_condition_ex_offers_sub( $match, $operator, $value ) {
    	var_dump('Hello!'); // I can't see that message on frontend
    	if ( ! isset( WC()->cart ) ) return $match;
            // The condition goes like this: Sum all products prices inside cart.
            // Exclude products that belongs to 'offers' category
            // (maybe is better to exclude products that has a sales price but
            // I couldn't figured it out).
    	$subtotal = 0;
    	foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    		$product = $cart_item['data'];
    		$quantity = $cart_item['quantity'];
    
    		if ( !has_term('offers', 'product_cat', $product->id) ) { // maybe this line needs to be changed with a condition 'if is on sale'.
    			$products_subtotal = $product->get_price() * $quantity;
    			$subtotal = $subtotal + $products_subtotal;
    		}
    	}
    
    	if ( '==' == $operator ) :
    		$match = ( $subtotal == $value );
    	elseif ( '!=' == $operator ) :
    		$match = ( $subtotal != $value );
    	elseif ( '>=' == $operator ) :
    		$match = ( $subtotal >= $value );
    	elseif ( '<=' == $operator ) :
    		$match = ( $subtotal <= $value );
    	endif;
    
    	return $match;
    }
    add_action( 'wafs_match_condition_ex_offers_sub', 'wafs_match_condition_ex_offers_sub', 10, 4 );
    
    • This reply was modified 8 years, 4 months ago by Apostolis.
    • This reply was modified 8 years, 4 months ago by Apostolis.
    Plugin Author Jeroen Sormani

    (@sormano)

    Hi,

    I see that the add_action all the way at the bottom is incorrect. This should be ‘wafs_match_condition_offers’ -> end with the condition slug.

    That said, I’m not even sure if the var_dump will show at the front-end at all times… That doesn’t have to be a indicator..

    Cheers,
    Jeroen

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exclude products that are ‘on sale’’ is closed to new replies.