Wooommerce Códigos php

                  /***
Crea una función que diga si el artículo vendido de woocomerce tiene envío o recogida local teniendo el id del pedido

https://chat.openai.com/share/2a678bd5-4147-480b-9fd5-e486538fed6e
**/

/***
CodeWp
**/
<?php
/**
 * cwpai_check_shipping_method
 * Returns whether the given order_id has a shipping method of "Local Pickup" or not
 *
 * @param int $order_id The ID of the order to check
 * @return bool True if "Local Pickup" is the shipping method, false otherwise
 */
function cwpai_check_shipping_method($order_id) {
    $order = wc_get_order($order_id); // Get the order object

    $shipping_methods = $order->get_shipping_methods(); // Get an array of all shipping methods for the order
    
    foreach ($shipping_methods as $shipping_method) { // Loop through each shipping method
        if ($shipping_method->get_method_id() === 'local_pickup') { // Check if the method ID matches "local_pickup"
            return true; // If so, we have local pickup and return true
        }
    }

    return false; // If we loop through all shipping methods and don't find "local_pickup", return false
}