THIS THREAD HAS BEEN CLOSED.

Membuat Metode Pembayaran COD untuk J&T Saja
Updated on April 12, 2021 in Plugin Ongkos Kirim
6 on April 9, 2021

Halo. Saya mau menampilkan metode pembayaran COD untuk kurir J&T saja. Berikut code saya:

/**
* Filter payment gateways
*/
function my_custom_available_payment_gateways( $gateways ) {

$chosen_shipping_rates = WC()->session->get( ‘chosen_shipping_methods’ );

// When ‘J&T’ has been chosen as shipping rate
if ( ! in_array( ‘pok-jnt-0’, $chosen_shipping_rates) ) :

// Remove bank transfer payment gateway
unset( $gateways[‘cod’] );

endif;

return $gateways;

}
add_filter( ‘woocommerce_available_payment_gateways’, ‘my_custom_available_payment_gateways’ );

Yang jadi kendala adalah ID ‘pok-jnt-0’ yang dipakai hanya bisa untuk kecamatan/lokasi tertentu saja. Adakah ID yang bisa saya pakai untuk select J&T secara keseluruhan?

Terimakasih.

  • Liked by
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off
Sorry, our support is not available at this time. We will reply at the next working hour.

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

Moderator 0 on April 12, 2021

Halo,

Kodenya bisa diupdate menjadi seperti ini:

function my_custom_available_payment_gateways( $gateways ) {

$chosen_shipping_rates = WC()->session->get( ‘chosen_shipping_methods’ );
$chosen_shipping_rates = isset($chosen_shipping_rates[0]) ? $chosen_shipping_rates[0] : ”;

$is_jnt = strpos( $chosen_shipping_rates, ‘pok-jnt’ );

if( $is_jnt === false ) {
unset( $gateways[‘cod’] );
}

return $gateways;
}
add_filter( ‘woocommerce_available_payment_gateways’, ‘my_custom_available_payment_gateways’ );

Sebelumnya pastikan metode pembayaran Cash On Delivery sudah diaktifkan di setting payment woocommerce-nya.

Salam,
Tonjoostudio Support.

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off
Sorry, our support is not available at this time. We will reply at the next working hour.

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

Message :
0 on April 12, 2021

Barusan saya coba kodenya, tapi COD nya masih nampil di kurir lain nih.

Tapi saya ada kode lain yang work. Ini kodenya:

add_filter( ‘woocommerce_available_payment_gateways’, ‘filter_available_payment_gateways’);

function filter_available_payment_gateways( $available_gateways ) {

if ( ! ( is_checkout_pay_page() ) ) {

$gateways_to_disable = array(‘cod’);
$shipping_methods = array( ‘pok-SAP-0′,’pok-SAP-1′,’pok-jne-0′,’pok-jne-1′,’pok-jne-2′,’pok-jne-3′,’pok-jne-4′,’pok-jne-5′,’pok-jne-6′,’pok-jne-7′,’pok-jne-8′,’pok-jne-9′,’pok-jne-10′,’pok-jne-11′,’pok-jne-12′,’pok-jne-13′,’pok-jne-14′,’pok-jne-15′,’pok-jne-16′,’pok-jne-17′,’pok-jne-18′,’pok-jne-19′,’pok-jne-20′,’pok-jne-21′,’pok-jne-22′,’pok-jne-23′,’pok-jne-24′,’pok-jne-25′,’pok-jne-26′,’pok-jne-27′,’pok-jne-28′,’pok-jne-29′,’pok-jne-30′,’pok-jne-31′,’pok-jne-32′,’pok-jne-33′,’pok-jne-34′,’pok-sicepat-0′,’pok-sicepat-1′,’pok-sicepat-2′,’pok-sicepat-3′,’pok-sicepat-4′,’pok-sicepat-5′,’pok-sicepat-6′,’pok-sicepat-7′,’pok-sicepat-8′,’pok-sicepat-9′,’pok-sicepat-10’ );
$disable_gateways = false;

// Check if we need to disable gateways
foreach ( $shipping_methods as $shipping_method ) {
if ( strpos( WC()->session->get( ‘chosen_shipping_methods’ )[0], $shipping_method ) !== false ) $disable_gateways = true;
}

// If so, disable the gateways
if ( $disable_gateways ) {
foreach ( $available_gateways as $id => $gateway ) {
if ( in_array( $id, $gateways_to_disable ) ) {
unset( $available_gateways[$id] );
}
}
}
return $available_gateways;
}
else { return $available_gateways;
}
}

Mohon dibantu supaya lebih efisien. Terimakasih!

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off
Sorry, our support is not available at this time. We will reply at the next working hour.

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

Message :
Moderator 0 on April 12, 2021

Bisa dikirimkan bukti kalau kodenya tidak jalan, akan lebih baik jika berbentuk video screencast, dan juga pastikan hanya satu kode yang meng-hook woocommerce_available_payment_gateways.

Salam,
Tonjoostudio Support.

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off
Sorry, our support is not available at this time. We will reply at the next working hour.

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

Message :
0 on April 12, 2021

Ini min,
Video kode gagal : https://youtu.be/k1cuWoZeCAQ

Saya sertakan juga video kode yang berhasil: https://youtu.be/65Yt0qoHZvs

Terimakasih.

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off
Sorry, our support is not available at this time. We will reply at the next working hour.

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

Message :
Moderator 0 on April 12, 2021

Kodenya perlu untuk disesuaikan, silakan di edit untuk tanda petiknya (petik yg dikode gagal itu bukan petik untuk standard code)

silakan tanda petiknya dihapus dulu, kemudian di ketik lagi.

""

Salam,
Tonjoostudio Support.

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off
Sorry, our support is not available at this time. We will reply at the next working hour.

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

Message :
0 on April 12, 2021

Sipp sudah bisa.
Terimakasih banyak supportnya

  • Liked by
Cancel
Support Hours:
Weekdays: 09.00 - 17.00
Weekend: Off
Sorry, our support is not available at this time. We will reply at the next working hour.

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 .