Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Vitor Paladini

    (@vtrpldn)

    Hey! I think I’ve made it!

    It’s not as elegant as I’d like to be but it’s working. I have used Claudio’s “wc_payment_discounts_row” filter to hide the returned html and nullified the discount the hard way.

    add_action('woocommerce_calculate_totals', 'remove_discount');
    function remove_discount(){
    	global $woocommerce;
    
    	if (isset($_POST['shipping_method'])){
    		$metodo = $_POST['shipping_method'];
    		if ($metodo[0] == 'local_delivery'){	
    
    			add_filter( 'wc_payment_discounts_row', 'hide_price', 10 );
    			$woocommerce->cart->discount_total = 0;
    
    		}
    	}
    }
    
    function hide_price($html){
    	$html = "";
    	return $html;
    }

    If anyone have a better solution to propose I will be glad to implement it.

    Thread Starter Vitor Paladini

    (@vtrpldn)

    Okay, I think I’m making progress so far.

    add_action('woocommerce_calculate_totals', 'teste');
    function teste(){
    	global $wc_payment_discounts;
    
    	if (isset($_POST['shipping_method'])){
    		$metodo = $_POST['shipping_method'];
    		if ($metodo[0] == 'local_delivery'){
    			remove_action( 'woocommerce_calculate_totals', array( $wc_payment_discounts, 'add_discount' ) );
    			remove_action( 'woocommerce_review_order_before_order_total', array( $wc_payment_discounts, 'discount_display' ) );
    		}
    	}
    }

    But still, $wc_payment_discounts is returning NULL, I guess I’m missing something vital right there.

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