Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Alexander Georgiev

    (@ageorgiev)

    Ok, I manage to do it with the 2 filters. If anyone is interested:

    $single_price        = wc_get_price_excluding_tax($product, array(‘qty’ => 1));    $row_price = (float) $single_price * (float) $quantity;

    function crew_b2b_prices_rounding($price, $qty, $product) {
        $price = number_format($price, wc_get_price_decimals()); //returned format must be 0,08. No extra digits after.
        return $price;
    }
    add_filter('woocommerce_get_price_excluding_tax', 'crew_b2b_prices_rounding', 10, 3);
    
    function subtotal() {function crew_b2b_product_subtotal_rounding($product_subtotal, $product, $quantity) {
    if ($product->is_taxable()) {
    if (!WC()->cart->display_prices_including_tax()) {
    $single_price        = wc_get_price_excluding_tax($product, array('qty' => 1));
                $row_price = (float) $single_price * (float) $quantity;
                $product_subtotal = wc_price($row_price);
    }
    }
    }
    add_filter('woocommerce_cart_product_subtotal', 'crew_b2b_product_subtotal_rounding', 10, 3);
    
    function crew_b2b_cart_totals_rounding($cart) {
    function crew_b2b_prices_rounding($price, $qty, $product) {
        $price = number_format($price, wc_get_price_decimals()); //returned format must be 0,08. No extra digits after.
        return $price;
    }
    add_filter('woocommerce_get_price_excluding_tax', 'crew_b2b_prices_rounding', 10, 3);
    
    function subtotal() {function crew_b2b_product_subtotal_rounding($product_subtotal, $product, $quantity) {
    if ($product->is_taxable()) {
    if (!WC()->cart->display_prices_including_tax()) {
    $single_price        = wc_get_price_excluding_tax($product, array('qty' => 1));
                $row_price = (float) $single_price * (float) $quantity;
                $product_subtotal = wc_price($row_price);
    }
    }
    }
    add_filter('woocommerce_cart_product_subtotal', 'crew_b2b_product_subtotal_rounding', 10, 3);
    
    function crew_b2b_cart_totals_rounding($cart) {
        if (!$cart->display_prices_including_tax()) {
    
    
            $subtotal = 0;
            $taxes = 0;
            $tax = new WC_Tax();
    
            $price_includes_tax = false;
            $product_taxes = array();
    
            foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
              
                $product_subtotal = 0;
    
                $product_id = $cart_item['product_id'];
                $product = wc_get_product($product_id);
                $single_price        = wc_get_price_excluding_tax($product, array('qty' => 1));
                $quantity = $cart_item['quantity'];
                $product_subtotal += $single_price * $quantity;
                $cart->cart_contents[$cart_item_key]['line_subtotal'] = $product_subtotal;
                $cart->cart_contents[$cart_item_key]['line_total'] = $product_subtotal;
                if ($product->is_taxable()) {
    
                    $tax_rates = $tax->get_rates($product->get_tax_class());
                    $subtotal_taxes = WC_Tax::calc_tax($product_subtotal, $tax_rates, $price_includes_tax);
    
                    $subtotal_tax = array_sum($subtotal_taxes);
                    $cart->cart_contents[$cart_item_key]['line_tax_data']['subtotal'] = $subtotal_taxes;
                    $cart->cart_contents[$cart_item_key]['line_tax_data']['total'] = $subtotal_taxes;
                    $cart->cart_contents[$cart_item_key]['line_subtotal_tax'] = number_format($subtotal_tax, wc_get_price_decimals());
                    $cart->cart_contents[$cart_item_key]['line_tax'] = number_format($subtotal_tax, wc_get_price_decimals());
                    $taxes += $cart->cart_contents[$cart_item_key]['line_subtotal_tax'];
    
                    //set product taxes here
                    foreach ($subtotal_taxes as $key => $value) {
                        if (isset($product_taxes[$key])) {
                            $product_taxes[$key] += $value; // Add to existing key
                        } else {
                            $product_taxes[$key] = $value; // Create new key
                        }
                    }
                }
                $subtotal += $cart->cart_contents[$cart_item_key]['line_subtotal'];           
            }
           
            $fees = $cart->get_fee_total();
          
            $shipping_total = $cart->get_shipping_total();
         
            $cart->set_cart_contents_taxes($product_taxes);
            $cart->set_total_tax($taxes);
            $total_tax = $cart->get_total_tax();      
            $discount = $cart->get_discount_total();
            $discount_tax = $cart->get_discount_tax();
            $total_discount = $discount + $discount_tax;
            $cart->set_subtotal($subtotal);
            $cart->set_total($subtotal + $total_tax + $shipping_total + $fees - $total_discount);      
        }
    }
    add_action('woocommerce_after_calculate_totals', 'crew_b2b_cart_totals_rounding');
    Thread Starter Alexander Georgiev

    (@ageorgiev)

    function goodbye_redirect() {     
        if( current_user_can('editor') || current_user_can('administrator') || is_page(32552) ) {  
          
        }
        else {
            wp_redirect( home_url('/goodbye/'), 301 );
           exit;
        }
    
    }
    add_action( 'template_redirect', 'goodbye_redirect' );

    Correct! I had to add the page (32552) and it worked 🙂 Thanks!

    Thread Starter Alexander Georgiev

    (@ageorgiev)

    I’ve manage to solved it by myself

    <select name="category_name">
    		<?php
    			 $terms = get_terms( 'category' );
    			 $count = count($terms);
    			 echo "<option value=''>All</option>";
     if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
         foreach ( $terms as $term ) {
    				echo "<option ".selected( $_GET['category_name'], $term->name )." value='$term->name'>$term->name</option>";
    			}
    		}
    		?>
    	</select>
    Thread Starter Alexander Georgiev

    (@ageorgiev)

    I’ve managed to do it manually by adding categories

    <select name="category_name">
    		<?php
    			$category_name = array(
    				'design' => 'Design',
    			);
    
    			foreach( $category_name as $value => $label ) {
    				echo "<option ".selected( $_GET['category_name'], $value )." value='$value'>$label</option>";
    			}
    		?>
    	</select>

    How should I do it automatically to display all the categories?

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