Forum Replies Created

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter an29

    (@an29)

    Hey
    Yes, I am using the built-in CSV importer. Could it be that I have over 10 000 products in the CSV? Looks like when i only try 3 it works fine. But when i try to use it for all the products, it skips like 9 000 products.

    Thread Starter an29

    (@an29)

    Little update;

    I think my problem lays here

    // Get weight & attribute values
    $product_weight = $cart_item['data']->get_weight();
    $ah_values = get_the_terms( $product->id, 'pa_ah');

    If i duplicate the $cart_item['data'], I get the white screen of death somehow.. Is there maybe another line of code that gets the values from the AH attribute?

    I guess the $cart_item['data'] gathers all the info from the products in the cart. And it only picks out the weight.. Is it possible to use a function to get both the attribute value and the weight and assign them to $product_weight and $ah_values

    • This reply was modified 2 years, 9 months ago by an29.
    Thread Starter an29

    (@an29)

    Thanks!

    Could you see if you see anything wrong with this code?

    function shipping_weight_and_lead_fee( $cart ) {
    			if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    				return;
    
    			/* SETTINGS */
    
    			// Specific categories
    			$specific_categories = array('Startbatterier', 'Buffalo Bull SHD', 'Li-ion MC batterier', 'NG – Gel Batterier', 'NH - H?yrate Batterier', 'NF – Frontmonterte Batterier', 'NM - 10?rs Batterier','NS - 5?rs Batterier', 'Running Bull', 'Power Bull PRO', 'Buffalo Bull', 'Starting Bull', 'Buffalo Bull SHD Pro', 'Power Bull', 'Bike Bull Classic 6V', 'Bike Bull Classic 12V', 'Bike Bull AGM 12V', 'Bike Bull GEL 12V', 'Bike Bull AGM PRO 12V', 'Freshpack', 'AGM', 'GEL');
    
    			// Initial fee
    			$fee = 0.60;
    			$feeah = 2.00;
    
    			/* END SETTINGS */
    
    			// Set variable
    			$total_weight = 0;
    			$total_ah = 0;
    
    			// Loop though each cart item
    			foreach ( $cart->get_cart() as $cart_item ) {
    				// Get product id
    				$product_id = $cart_item['product_id'];
    
    				// Get weight
    				$product_weight = $cart_item['data']->get_weight();
    				$ah_values = get_the_terms( $product->id, 'ah');
    
    				// NOT empty & has certain category     
    				if ( ! empty( $product_weight ) && has_term( $specific_categories, 'product_cat', $product_id ) ) {
    					// Quantity
    					$product_quantity = $cart_item['quantity'];
    
    					// Add to total
    					$total_weight += $product_weight * $product_quantity;
    				}
    				if ( ! empty( $ah_values ) && has_term( $specific_categories, 'product_cat', $product_id ) ) {
    					// Quantity
    					$product_quantity = $cart_item['quantity'];
    					$total_ah += $ah_values * $product_quantity;
    				}
    			}
    
    			if ( $total_weight > 0 ) {          
    				$cart->add_fee( __( 'Milj?tillegg' ), $fee * $total_weight, false );  
    				$cart->add_fee( __( 'Blytillegg' ), $feeah * $total_ah, false ); 
    			}
    
    		}
    		add_action( 'woocommerce_cart_calculate_fees', 'shipping_weight_and_lead_fee', 10, 1 );

    Im not that advanced yet. So i appreciate all the help i can get.

    Thread Starter an29

    (@an29)

    This is for simple products. It don’t have product variations.

    Thread Starter an29

    (@an29)

    Yes the ah value is set up in the attribute. I’d want to make a similar code to the one i’ve already created. Only this get the ah value. I don’t know how to get the ah value. I used this $product_weight = $cart_item[‘data’]->get_weight(); to get the weight. Is there a simular way to get a value from the attribute?

    Thread Starter an29

    (@an29)

    Thanks for the help! It works.

    Made my day

    Thread Starter an29

    (@an29)

    I’m aware of this plugin. However my problem is that i want to move categories to a new location. I cannot create new ones, because these categories have many different products in them, and it would take multiple days to give all a new category

    Thread Starter an29

    (@an29)

    Thread Starter an29

    (@an29)

    Hei igjen,

    Har pr?vd ? sl? av og p? plugins osv.. Hadde en backup til da det virket som jeg gikk tilbake til. Men det fungerer fortsatt ikke.

    S? raskt gjennom loggen, fant ingenting som var interessant.

    Thread Starter an29

    (@an29)

    Thank you for the answer and links! It works perfectly.

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