Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

woocommerce hiding shipping methods

$
0
0

Replies: 0

Hello,

i’m having some troubles with my shipping method options on woocommerce.

On my front-end i’m able to see the way it has to be (it is set correctly), but on any other devices it doesn’t show it properly.

On my site when free shipping is available (beyond 29,90$) it hides the shipping options. I’ve used those lines of code to do it:

function my_hide_shipping_when_free_is_available( $rates ) {
	$free = array();

	foreach ( $rates as $rate_id => $rate ) {
		if ( 'free_shipping' === $rate->method_id ) {
			$free[ $rate_id ] = $rate;
			break;
		}
	}

	return ! empty( $free ) ? $free : $rates;
}

add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 29,90 );

function custom_remove_default_et_pb_custom_search() {
	remove_action( 'pre_get_posts', 'et_pb_custom_search' );
	add_action( 'pre_get_posts', 'custom_et_pb_custom_search' );
}
add_action( 'wp_loaded', 'custom_remove_default_et_pb_custom_search' );

function custom_et_pb_custom_search( $query = false ) {
	if ( is_admin() || ! is_a( $query, 'WP_Query' ) || ! $query->is_search ) {
		return;
	}

	if ( isset( $_GET['et_pb_searchform_submit'] ) ) {
		$postTypes = array();
        
		if ( ! isset($_GET['et_pb_include_posts'] ) && ! isset( $_GET['et_pb_include_pages'] ) ) {
            $postTypes = array( 'post' );
        }

		if ( isset( $_GET['et_pb_include_pages'] ) ) {
            $postTypes = array( 'page' );
        }

		if ( isset( $_GET['et_pb_include_posts'] ) ) {
            $postTypes[] = 'post';
        } 

		/* BEGIN Add custom post types */
		$postTypes[] = 'product';
		/* END Add custom post types */

		$query->set( 'post_type', $postTypes );

		if ( ! empty( $_GET['et_pb_search_cat'] ) ) {
			$categories_array = explode( ',', $_GET['et_pb_search_cat'] );
			$query->set( 'category__not_in', $categories_array );
		}

		if ( isset( $_GET['et-posts-count'] ) ) {
			$query->set( 'posts_per_page', (int) $_GET['et-posts-count'] );
		}
	}
}

The fact is that under that 29,90 it doesn’t show the shipping options. So basically nobody is able to see the shipping methods options except me i guess.
Is it written correctly?

Could you help me out with this?
I don’t think there’s any correlation with other plugins (since i’m using just: WooCommerce Smart COD – but that relates only to (Cash on Delivery) Gateway payments).

Thank you very much who will answer to me


Viewing all articles
Browse latest Browse all 59525

Trending Articles