Home / Admin / Use Full Store Address in Ships From
Duplicate Snippet

Embed Snippet on Your Site

Use Full Store Address in Ships From

By default the Ships From metadata displayed under the add to cart button only shows the country. The following code snippet will replace this with the full Store address.

Code Preview
php
<?php
add_filter( 'wcv_product_ships_from', 'ships_from_address' );
function ships_from_address( $field ){
 
    global $post, $product;
 
    $shipping_disabled = wc_string_to_bool( get_option( 'wcvendors_shipping_management_cap', 'no' ) );
    $post              = get_post( $product->get_id() );
 
    if ( $product->needs_shipping() && ! $shipping_disabled && WCV_Vendors::is_vendor( $post->post_author ) ) {
 
        $vendor_id      = WCV_Vendors::get_vendor_from_product( $product->get_id() );
        $is_vendor      = WCV_Vendors::is_vendor( $vendor_id );
        $store_rates    = (array) get_user_meta( $vendor_id, '_wcv_shipping', true );
        $from_address   = ( $store_rates && array_key_exists( 'shipping_from', $store_rates ) && $store_rates['shipping_from'] == 'other' ) ? $store_rates['shipping_address'] : wcv_format_store_address( $vendor_id );
 
        if ( is_array( $from_address ) ) $from_address = implode( ', ', $from_address );
 
    }
 
    $field[ 'store_country' ] =  $from_address;
 
    return $field;
}

Comments

Add a Comment