Support » Plugin: WooCommerce » Virtual Products Add Shipping

  • Resolved timmelody

    (@timmelody)


    Hi there,

    I am trying to gather alternate shipping address info for virtual products

    But when I add this recommended code:

    add_filter( ‘woocommerce_cart_needs_shipping’, ‘__return_true’ );

    it returns and error of “Invalid shipping method” at the last step of checkout, when trying to pay.

    Any idea why this might be happening and how I can fix it?

    Thanks for help!

    https://wordpress.org/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • kimsf

    (@kimsf)

    Why did you need to add shipping to virtual products? Just wondering since there might be a better solution to a problem.

    Why not just edit form-shipping.php so that the ship_to_different_address by default is checked? (Not the best solution but it gets the job done).

    timmelody

    (@timmelody)

    What would be the correct way to edit this in order to use that solution?

    <?php
    			if ( empty( $_POST ) ) {
    
    				$ship_to_different_address = get_option( 'woocommerce_ship_to_destination' ) === 'shipping' ? 1 : 0;
    				$ship_to_different_address = apply_filters( 'woocommerce_ship_to_different_address_checked', $ship_to_different_address );
    
    			} else {
    
    				$ship_to_different_address = $checkout->get_value( 'ship_to_different_address' );
    
    			}
    		?><?php
    			if ( empty( $_POST ) ) {
    
    				$ship_to_different_address = get_option( 'woocommerce_ship_to_destination' ) === 'shipping' ? 1 : 0;
    				$ship_to_different_address = apply_filters( 'woocommerce_ship_to_different_address_checked', $ship_to_different_address );
    
    			} else {
    
    				$ship_to_different_address = $checkout->get_value( 'ship_to_different_address' );
    
    			}
    		?>
    Plugin Author Mike Jolley

    (@mikejolley)

    If you enabled ‘woocommerce_cart_needs_shipping’ you’re telling WC that you need shipping costs. You don’t want this.

    Use the woocommerce_cart_needs_shipping_address filter instead.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Virtual Products Add Shipping’ is closed to new replies.