@MahdiY
از کد های زیر برای حذف فیلد های اضافی برای محصولات مجازی استفاده می کنم
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 1000, 1 );
function custom_override_checkout_fields( $fields ) {
global $woocommerce;
$hasPhysicalProduct = false;
if ( ! empty( $woocommerce->cart->cart_contents ) ) {
// Cart is not empty, now loop through the cart
$cart = $woocommerce->cart->get_cart();
foreach ( $cart as $key => $values ) {
$_product = wc_get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );
if ( ! empty( $_product ) && $_product->exists() && $values['quantity'] > 0 ) {
if ($_product->virtual == 'no' && $_product->downloadable == 'no') {
$hasPhysicalProduct = true;
break;
}
}
}
}
if ($hasPhysicalProduct == false)
{
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
}
return $fields;
}
منتهی بعد از بروزرسانی به ورژن 1.1 وقتی محصول مجازی باشه خطای زیر میده و سفارش ثبت نمیشه
ممنون میشم بررسی بفرمایید.