• Resolved bennymcl

    (@bennymcl)


    So, I need to edit the wc_cart_totals_shipping_html function in the wc-cart-functions.php file located in the includes folder.

    I can’t, for the life of me, figure out how to properly override this function. It doesn’t seem to have filters or actions attached to it in anyway… so what do I do? Anyone have any suggestions at all? Basically, I need to send custom values through the ajax when someone clicks a shipping option and sending the data through the system.

    I essentially need to add values to the “wc_get_template” and pass through the variables

    function wc_cart_totals_shipping_html() {
    	$packages           = WC()->shipping->get_packages();
    	$first              = true;
    
    	foreach ( $packages as $i => $package ) {
    		$chosen_method = isset( WC()->session->chosen_shipping_methods[ $i ] ) ? WC()->session->chosen_shipping_methods[ $i ] : '';
    		$product_names = array();
    
    		if ( count( $packages ) > 1 ) {
    			foreach ( $package['contents'] as $item_id => $values ) {
    				$product_names[ $item_id ] = $values['data']->get_name() . ' ×' . $values['quantity'];
    			}
    			$product_names = apply_filters( 'woocommerce_shipping_package_details_array', $product_names, $package );
    		}
    
    		wc_get_template(
    			'cart/cart-shipping.php', array(
    				'package'                  => $package,
    				'available_methods'        => $package['rates'],
    				'show_package_details'     => count( $packages ) > 1,
    				'show_shipping_calculator' => is_cart() && $first,
    				'package_details'          => implode( ', ', $product_names ),
    				/* translators: %d: shipping package number */
    				'package_name'             => apply_filters( 'woocommerce_shipping_package_name', ( ( $i + 1 ) > 1 ) ? sprintf( _x( 'Shipping %d', 'shipping packages', 'woocommerce' ), ( $i + 1 ) ) : _x( 'Shipping', 'shipping packages', 'woocommerce' ), $i, $package ),
    				'index'                    => $i,
    				'chosen_method'            => $chosen_method,
    				'formatted_destination'    => WC()->countries->get_formatted_address( $package['destination'], ', ' ),
    				'has_calculated_shipping'  => WC()->customer->has_calculated_shipping(),
    			)
    		);
    
    		$first = false;
    	}
    }

    Many thanks for all who can maybe help me.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Editing Core files in the right way?’ is closed to new replies.