Ask your WordPress questions! Pay money and get answers fast! (more info)

Woocommerce - customize shipping options in cart WordPress

Hi,

I got a Woocommerce question.

How do we hook into the "local_pickup" shipping class and add a dropdown select box with options?

Options example:
[Select shipping]
USA
Canada
UK

The "local pickup" shipping class comes as standard with one radio button, but if you got several local pickup locations, you might want to add more than one options to choose from.

The action and filter reference is located in url below. I'm not that familier of using them, but maybe you are?

http://docs.woothemes.com/document/hooks/

Answers (2)

2014-05-08

Kyle answers:

Did you know there is a plugin for handling just this?

[[LINK href="http://www.woothemes.com/products/local-pickup-plus/?utm_source=docs&utm_medium=docssite&utm_campaign=docs"]]http://www.woothemes.com/products/local-pickup-plus/?utm_source=docs&utm_medium=docssite&utm_campaign=docs[[/LINK]]


Kyle comments:

This should do the trick though

[[LINK href="http://pastie.org/9157317"]]http://pastie.org/9157317[[/LINK]]

add_filter( 'woocommerce_checkout_fields' , 'custom_store_pickup_field');

function custom_store_pickup_field( $fields ) {
$fields['shipping']['store_pickup'] = array(
'type' => 'select',
'options' => array(
'option_1' => 'Option 1 text',
'option_2' => 'Option 2 text',
'option_3' => 'Option 2 text'
),
'label' => __('Store Pick Up Location', 'woocommerce'),
'required' => false,
'class' => array('store-pickup form-row-wide'),
'clear' => true
);

return $fields;
}


Kyle comments:

You'll want to add this too:

add_action( 'woocommerce_checkout_update_order_meta', 'store_pickup_field_update_order_meta' );
function store_pickup_field_update_order_meta( $order_id ) {
if ( $_POST[ 'store_pickup' ] )
update_post_meta( $order_id, 'Store PickUp Location', esc_attr( $_POST[ 'store_pickup' ] ) );
}


That will save the name of the location to the Order for informational purposes


haurs comments:

Thanks for the code, but this doesn't work. I have already tried that one.

I believe it needs to hook into one of the actions or filters the outputs the shipping option.

Any idea? http://docs.woothemes.com/document/hooks/

2014-05-09

Bob answers:

by following this tutorial I get output at checkout page in shipping section.
[[LINK href="http://calebserna.com/how-to-add-multiple-local-pickup-locations-to-woocommerce/"]]http://calebserna.com/how-to-add-multiple-local-pickup-locations-to-woocommerce/[[/LINK]]

to show it in billing section you can try in code.

$fields['billing']['store_pickup'] = array(


haurs comments:

Thank you Bob, but this is also the same code as Kyle (above) provided. I'm trying to figure our how to place it below the personal billing/shipping fields and have it show where the actual shipping details are shown - which is at the bottom of the shopping basket as well as at the bottom of cart. Hope that make sense. Thanks again!