THIS THREAD HAS BEEN CLOSED.

Hide checkout field saat produk virtual produk only
Updated on June 15, 2023 in Plugin Ongkos Kirim
Premium  7 on June 14, 2023

kita bikin plugin untuk hide beberapa checkout field saat virtual produk di halaman checkout. beberapa billing field berhasil kita hide, tapi untuk field City, District dan insurance masih tetap muncul ga ikut ke hide. kita gatau nama parameternya.

apakah ada yang perlu saya tambahkan di codenya?

ini code yang kita pake:

ini code yang kita pake di pluginnya:
add_filter( 'woocommerce_checkout_fields', 'bbloomer_simplify_checkout_virtual' );

function bbloomer_simplify_checkout_virtual( $fields ) {
$only_virtual = true;
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Check if there are non-virtual products
if ( ! $cart_item['data']->is_virtual() ) $only_virtual = false;
}
if ( $only_virtual ) {
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_city']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_state']);
add_filter( 'woocommerce_enable_order_notes_field', '__return_false' );
}
return $fields;
}

  • Liked by
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off

By using the forum you are agree with tonjoo studio license agreement

Premium  0 on June 14, 2023

add_filter( ‘woocommerce_checkout_fields’, ‘bbloomer_simplify_checkout_virtual’ );

function bbloomer_simplify_checkout_virtual( $fields ) {
$only_virtual = true;
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Check if there are non-virtual products
if ( ! $cart_item[‘data’]->is_virtual() ) $only_virtual = false;
}
if ( $only_virtual ) {
unset($fields[‘billing’][‘billing_company’]);
unset($fields[‘billing’][‘billing_address_1’]);
unset($fields[‘billing’][‘billing_address_2’]);
unset($fields[‘billing’][‘billing_city’]);
unset($fields[‘billing’][‘billing_postcode’]);
unset($fields[‘billing’][‘billing_country’]);
unset($fields[‘billing’][‘billing_state’]);
add_filter(‘woocommerce_enable_order_notes_field’, ‘__return_false’ );
}
return $fields;
}

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off

By using the forum you are agree with tonjoo studio license agreement

Message :
Moderator 0 on June 14, 2023

Halo
Coba gunakan hook berikut

add_action( ‘pok_hooks_addresses’, function( $class ) {
if ( ! WC()->cart->needs_shipping() ) {
remove_filter( ‘woocommerce_checkout_fields’, array( $class, ‘custom_checkout_fields’ ) );
remove_filter( ‘woocommerce_billing_fields’, array( $class, ‘custom_billing_fields’ ) );
remove_filter( ‘woocommerce_shipping_fields’, array( $class, ‘custom_shipping_fields’ ) );
remove_filter( ‘woocommerce_get_country_locale_default’, array( $class, ‘country_locale_default’ ) );
remove_filter( ‘woocommerce_get_country_locale’, array( $class, ‘country_locale’ ) );
}
} );

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off

By using the forum you are agree with tonjoo studio license agreement

Message :
Premium  0 on June 14, 2023

ini replace code saya sebelumnya atau ditambahkan di code saya sebelumnya?

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off

By using the forum you are agree with tonjoo studio license agreement

Message :
Moderator 0 on June 14, 2023

bisa ditambahkan. code di atas berfungsi untuk mematikan kustomisasi yang dilakukan oleh plugin kami

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off

By using the forum you are agree with tonjoo studio license agreement

Message :
Premium  0 on June 14, 2023

oke berarti saya coba tambahkan di bagain bawah code saya ya

codenya jadi gini ya?


<?php
/**
* Plugin Name: Virtual Product Hide Billing
* Description: Hides billing information checkout fields for virtual products.
* Version: 1.1.1
* Author: Dikdik Herdiana
* Author URI: Your Website
*/

// Exit if accessed directly.
if (!defined(&#039;ABSPATH&#039;)) {
exit;
}

add_filter( &#039;woocommerce_checkout_fields&#039;, &#039;bbloomer_simplify_checkout_virtual&#039; );

function bbloomer_simplify_checkout_virtual( $fields ) {
$only_virtual = true;
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// Check if there are non-virtual products
if ( ! $cart_item[&#039;data&#039;]->is_virtual() ) $only_virtual = false;
}
if ( $only_virtual ) {
unset($fields[&#039;billing&#039;][&#039;billing_company&#039;]);
unset($fields[&#039;billing&#039;][&#039;billing_address_1&#039;]);
unset($fields[&#039;billing&#039;][&#039;billing_address_2&#039;]);
unset($fields[&#039;billing&#039;][&#039;billing_city&#039;]);
unset($fields[&#039;billing&#039;][&#039;billing_postcode&#039;]);
unset($fields[&#039;billing&#039;][&#039;billing_country&#039;]);
unset($fields[&#039;billing&#039;][&#039;billing_state&#039;]);
add_filter( &#039;woocommerce_enable_order_notes_field&#039;, &#039;__return_false&#039; );
}
return $fields;
}

add_action(&#039;pok_hooks_addresses&#039;, function ($class) {
if (!WC()->cart->needs_shipping()) {
remove_filter(&#039;woocommerce_checkout_fields&#039;, array($class, &#039;custom_checkout_fields&#039;));
remove_filter(&#039;woocommerce_billing_fields&#039;, array($class, &#039;custom_billing_fields&#039;));
remove_filter(&#039;woocommerce_shipping_fields&#039;, array($class, &#039;custom_shipping_fields&#039;));
remove_filter(&#039;woocommerce_get_country_locale_default&#039;, array($class, &#039;country_locale_default&#039;));
remove_filter(&#039;woocommerce_get_country_locale&#039;, array($class, &#039;country_locale&#039;));
}
});

?>

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off

By using the forum you are agree with tonjoo studio license agreement

Message :
Premium  0 on June 14, 2023

codenya error
There has been a critical error on this website. Please check your site admin email inbox for instructions.

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off

By using the forum you are agree with tonjoo studio license agreement

Message :
Moderator 0 on June 15, 2023

maaf, adakah pesan error yang ditampilkan?

jika berkenan, kami akan melakukan update pada plugin kami untuk menghandle kasus produk virtual ini, dan akan kami rilis pada patch berikutnya

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off

By using the forum you are agree with tonjoo studio license agreement

Message :
Loading more replies
You are not logged in

Please login here or simply sign up here .