Va oferim mai jos codul necesar pentru a dezactiva metoda de plata ramburs pentru 2 sau mai multe metode de livrare la locker. Snippet-ul de mai jos este pentru dezactivarea metodei de plata nativa a WooCommerce denumita COD (Cash on delivery) pentru livrarea la FANBOx si la GLS BOX. Daca aveti metode de plata custom, adaptati codul. Daca doriti sa extindeti codul si pentru alte metode de livrare, adaptati de asemenea codul incluzand denumirea metodelor respective in array-ul boldat:
/**
* Disables Cash on Delivery (COD) payment method for specific shipping methods.
*
* @param array $available_gateways Array of available payment gateways.
* @return array Modified array of payment gateways.
*/
function curiero_disable_cod_for_shipping_methods($available_gateways) {
// Only proceed if WooCommerce is active and we have a session.
// Also, ensure 'chosen_shipping_methods' is set in the session.
if (!class_exists('WooCommerce') || !WC()->session || !WC()->session->get('chosen_shipping_methods')) {
return $available_gateways;
}
// Get the chosen shipping methods for all packages.
// This is an array, e.g., ['flat_rate:1', 'local_pickup:2']
$chosen_shipping_methods_with_instances = WC()->session->get('chosen_shipping_methods');
// Define the shipping method IDs for which COD should be disabled.
$target_shipping_method_ids = array(
'curiero_mygls_box',
'curiero_fan_fanbox',
// Adaugati aici mai multe metode daca este nevoie
);
$disable_cod = false;
// Iterate through each chosen shipping method (in case of multiple packages/rates per order).
foreach ($chosen_shipping_methods_with_instances as $method_with_instance) {
// Shipping method IDs from the session often include an instance ID,
// e.g., 'flat_rate:2'. We need to extract the base method ID.
$parts = explode(':', $method_with_instance, 2); // Limit to 2 parts to be safe
$chosen_method_id = $parts[0];
// Check if the current chosen shipping method ID is in our target list.
if (in_array($chosen_method_id, $target_shipping_method_ids)) {
$disable_cod = true;
break; // Found a match, no need to check further.
}
}
// If any of the chosen shipping methods match our target list, disable COD.
if ($disable_cod) {
if (isset($available_gateways['cod'])) {
unset($available_gateways['cod']);
}
}
return $available_gateways;
}
add_filter('woocommerce_available_payment_gateways', 'curiero_disable_cod_for_shipping_methods', 10, 1);