Syntax error
-
Hi guys, I have a syntax problem in this code, could someone help me? I don’t know how to code, this was done by someone else and I tried to adapt.
Error: We encountered an error activating your snippet, please check the syntax and try again.// // // Get customer's state
$state = get_customer_state(); // Get product types and shipping classes in cart
$product_types = array();
$shipping_classes = array();
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product = $cart_item['data'];
$product_types[] = $product->get_type();
$shipping_classes[] = $product->get_shipping_class_id();
} // Determine available shipping methods
$available_methods = array();
if ( in_array( 'local_delivery', $product_types ) && in_array( 'standard', $shipping_classes ) && in_array( $state, array( 'RS', 'SC', 'MG', 'RJ', 'PR', 'ES', 'MS', 'SP' ) ) ) {
// Case 1: Local Delivery (Standard) in eligible states - show only SEDEX and Free Shipping
$available_methods[] = 'SEDEX';
$available_methods[] = 'free_shipping';
} elseif ( in_array( 'local_delivery', $product_types ) && in_array( 'standard', $shipping_classes ) ) {
// Case 2: Local Delivery (Standard) in other states - show only PAC and SEDEX
$available_methods[] = 'PAC';
$available_methods[] = 'SEDEX';
} elseif ( in_array( 'dropshipping', $product_types ) && in_array( 'free_shipping', $shipping_classes ) ) {
// Case 3: Dropshipping (Free Shipping) - show only Free Shipping
$available_methods[] = 'free_shipping';
} elseif ( in_array( 'local_delivery', $product_types ) ) {
// Case 4: Other - use Local Delivery as default
$available_methods[] = 'local_delivery';
} else {
// Case 5: Free Shipping (default)
$available_methods[] = 'free_shipping';
} // Remove unavailable shipping methods
$unavailable_methods = array_diff( WC()->shipping->get_shipping_methods(), $available_methods );
foreach ( $unavailable_methods as $unavailable_method ) {
unset( WC()->shipping->shipping_methods[ $unavailable_method ] );
}
?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Syntax error’ is closed to new replies.