Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter trunkx

    (@trunkx)

    maybe if got another solution for this.
    I think its enough when i add a ~ infront of the gramm price and only show 2 commas like it is.

    But then i run into the next problem =)
    I only want to show the ~ before prices witch are in a defined main category. All products witch are not in this product-category(or subcategory) should have the standard price output.

    For showing “per gramm” after the price for this main category i have tried to change the /loop/price.php like this:

    <?php
    /**
     * Loop Price
     *
     * @author 		WooThemes
     * @package 	WooCommerce/Templates
     * @version     1.6.4
     */
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    global $product;
    ?>
    <?php if ( $price_html = $product->get_price_html() ) : ?>
    <?php 
    	//Check for parent category - if id =23  show other price
    	
    	//Get parent category
    	global $post;
    $prod_terms = get_the_terms( $post->ID, 'product_cat' );
    foreach ($prod_terms as $prod_term) {
    
        // gets product cat id
        $product_cat_id = $prod_term->term_id;
    
        // gets an array of all parent category levels
        $product_parent_categories_all_hierachy = get_ancestors( $product_cat_id, 'product_cat' );  
    
        // This cuts the array and extracts the last set in the array
        $last_parent_cat = array_slice($product_parent_categories_all_hierachy, -1, 1, true);
        foreach($last_parent_cat as $last_parent_cat_value){
            // $last_parent_cat_value is the id of the most top level category, can be use whichever one like
            if($last_parent_cat_value == 23):
    			$product_price_per_100g = $product->get_price_including_tax() * 100;
    		?>
    			<span class="product_price headerfont"><?php echo $price_html." /g"; ?></span>
    			 
    			
    		<?php
    			echo number_format(
    				$product_price_per_100g, // zu konvertierende zahl
    				2,     // Anzahl an Nachkommastellen
    				",",   // Dezimaltrennzeichen
    				"."    // 1000er-Trennzeichen
    			);
    			echo " ".get_woocommerce_currency();
    			echo " /100g";
    		else:
    ?>
    			<?php $product_price_per_g = $product->get_price_including_tax(); ?>
    			<span class="product_price headerfont"><?php echo $product_price_per_g; ?></span>
    			
    		<?php endif; ?>
    		<?php
        } 
    
    }//foreach ENDE
    	
    
    ?>
    <?php endif;?>

    The price output on this defined category and sub-categories was working but all other products witch was not in this categories didn’t output any price after.

    Do you maybe have an idea what is wrong with this script ?

    Thread Starter trunkx

    (@trunkx)

    Ok i understand what you mean but its only for the customer view. it should not change the behavior of calculation.

    I sell the products in my shop gramm wise, so when i enter 0,106 € per gramm and set decimals to 2 in woo commerce settings i will get the price 0,11 for this product (if vat is not considered)

    0,11 € * 100g = 11 € but the real price for the product at the checkout is 10,60 €

    That’s why i need it to show with 3 commas then it should be correct cause:

    0,106 € x 100g = 10,60€

    Thread Starter trunkx

    (@trunkx)

    thank you for your answer. The problem is that i only need the price with 3 commas in one place. When i change it there to 3 commas i have this price view in the whole shop.

    Thread Starter trunkx

    (@trunkx)

    Problem solved. after deactivate cross links on lexicon posts(Encyclopedia plugin) it seems to work.

    Thread Starter trunkx

    (@trunkx)

    thank you for nice support. that did it.

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