Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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, 1 month ago by Apostolis.
    • This reply was modified 8 years, 1 month ago by Apostolis.
    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, 2 months ago by Apostolis.

    Does this snippet works on premium version? I have tried it without success.

Viewing 3 replies - 1 through 3 (of 3 total)