Overriding the global $post in last version.
-
Hi!
After upgrading to the last version a couple of woocommerce plugins stop working correctly, after a little debugging I found out the problem is that you are loading the stores even when store_id == 0. And that override global $post.So in first instance I move the $store = wps_stores_fields( $store_id ); inside the if but I don’t know if it will play nice so I remove the filter completely returning the address at the begging (We are not using the email of the store). The first code is like this:
/** * Formatting shipping address for wc_pickup_store method * @version 1.7.1 * @return string Address with store information */ function wps_wc_order_get_formatted_shipping_address( $address, $raw_address, $order ) { $order_id = $order->get_id(); $store_name = wps_get_post_meta( $order_id, '_shipping_pickup_stores' ); // Get store title for this order $store_id = wps_get_store_id_by_name( $store_name ); if ( $store_id != 0 && $order->has_shipping_method( 'wc_pickup_store' ) ) { $store = wps_stores_fields( $store_id ); $address = WC()->countries->get_formatted_address( array( 'company' => sprintf( '%1$s: %2$s', apply_filters('wps_store_checkout_label', WPS()->title), $store_name ), 'address_1' => isset( $store['address'] ) ? wp_strip_all_tags( $store['address'] ) : '', 'city' => $store['city'] ?? '', 'phone' => $store['phone'] ?? '', 'country' => $store['store_country'] ?? '', 'postcode' => '' ) ); if ( $store_email = wps_get_email_address( $order, $store_id, true ) ) { $address .= '<br>' . sprintf( '%1$s: %2$s', __('Store email', 'wc-pickup-store'), $store_email ); } } return $address; } add_filter( 'woocommerce_order_get_formatted_shipping_address', 'wps_wc_order_get_formatted_shipping_address', 10, 3 );
The second version is:
/** * Formatting shipping address for wc_pickup_store method * @version 1.7.1 * @return string Address with store information */ function wps_wc_order_get_formatted_shipping_address( $address, $raw_address, $order ) { return $address; $order_id = $order->get_id(); $store_name = wps_get_post_meta( $order_id, '_shipping_pickup_stores' ); // Get store title for this order $store_id = wps_get_store_id_by_name( $store_name ); if ( $store_id != 0 && $order->has_shipping_method( 'wc_pickup_store' ) ) { $store = wps_stores_fields( $store_id ); $address = WC()->countries->get_formatted_address( array( 'company' => sprintf( '%1$s: %2$s', apply_filters('wps_store_checkout_label', WPS()->title), $store_name ), 'address_1' => isset( $store['address'] ) ? wp_strip_all_tags( $store['address'] ) : '', 'city' => $store['city'] ?? '', 'phone' => $store['phone'] ?? '', 'country' => $store['store_country'] ?? '', 'postcode' => '' ) ); if ( $store_email = wps_get_email_address( $order, $store_id, true ) ) { $address .= '<br>' . sprintf( '%1$s: %2$s', __('Store email', 'wc-pickup-store'), $store_email ); } } return $address; } add_filter( 'woocommerce_order_get_formatted_shipping_address', 'wps_wc_order_get_formatted_shipping_address', 10, 3 );
`
It is a really good plugin but is not playing nice with others.
Hope it helps to improve, regards.
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Overriding the global $post in last version.’ is closed to new replies.