Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Fix issues with inconsistent store shipping address meta fields in WCV Pro
- * Using the _wcv_shipping meta field array only
- */
- add_filter( 'get_user_metadata', function( $value, $object_id, $meta_key, $single ) {
- // Get values from _wcv_shipping shipping_address array
- if ( preg_match ( '/^_wcv_shipping_(.+)$/', $meta_key, $matches ) && in_array( $matches[ 1 ], array( 'from', 'address1', 'address2', 'city', 'state', 'country', 'postcode' ) ) ) {
- $shipping_data = get_user_meta($object_id, '_wcv_shipping', true);
- if ($matches[ 1 ] == 'from' )
- return array( @$shipping_data[ 'shipping_from' ] );
- else
- return array( @$shipping_data[ 'shipping_address' ][ $matches[ 1 ] ] );
- }
- return $value;
- }, 10, 4 );
- add_action( 'update_user_meta', function( $meta_id, $object_id, $meta_key, $_meta_value ) {
- // Store values in _wcv_shipping array and delete actual meta field value
- if ( preg_match ( '/^_wcv_shipping_(.+)$/', $meta_key, $matches ) && in_array( $matches[ 1 ], array( 'from', 'address1', 'address2', 'city', 'state', 'country', 'postcode' ) ) ) {
- $shipping_data = get_user_meta($object_id, '_wcv_shipping', true);
- if ( empty( $shipping_data ) )
- $shipping_data = array();
- if ($matches[ 1 ] == 'from' )
- $shipping_data[ 'shipping_from' ] = $_meta_value;
- else
- $shipping_data[ 'shipping_address' ][ $matches[ 1 ] ] = $_meta_value;
- update_user_meta( $object_id, '_wcv_shipping', $shipping_data);
- delete_user_meta( $object_id, $meta_key );
- }
- }, 10, 4 );
- add_filter( 'wcv_custom_user_fields', function ( $fields ) {
- // Fix "store state"
- $store_address = array();
- foreach( $fields[ 'store_address' ][ 'fields' ] as $k => $v ) {
- if ( $k == '_wcv_shipping_state' )
- $k = '_wcv_store_state';
- $store_address[ $k ] = $v;
- }
- $fields[ 'store_address' ][ 'fields' ] = $store_address;
- // Add "Shipping from" before shipping address
- $fields2 = array();
- foreach( $fields as $k => $v ) {
- if ($k == 'shipping_address')
- $fields2[ 'shipping_options' ] = array(
- 'title' => __( "Shipping", 'wcvendors-pro' ),
- 'fields' => array(
- '_wcv_shipping_from' => array(
- 'label' => __( 'Shipping from', 'wcvendors-pro' ),
- 'description' => __( 'Where products will be shipped from.', 'wcvendors-pro' ),
- //'class' => 'js_field-country',
- 'type' => 'select',
- 'options' => array(
- 'store_address' => __( 'Store Address', 'wcvendors-pro' ),
- 'other' => __( 'Store Shipping Address', 'wcvendors-pro' ),
- )
- ),
- )
- );
- $fields2[ $k ] = $v;
- }
- unset ( $fields2[ 'shipping_address' ][ 'fields' ][ '_wcv_store_phone' ] );
- return $fields2;
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement