Menambahkan Arahan Di Atas Tombol Buat Pesanan
add_action( 'woocommerce_review_order_before_submit', 'bbloomer_privacy_message_below_checkout_button' );
function bbloomer_privacy_message_below_checkout_button() {
echo '<p>JANGAN LUPA NANTI SETELAH TRANSFER, KONFIRMASI PEMBAYARAN VIA TOMBOL WA MELAYANG. BUDAYAKAN SABAR.</p>';
}
Menonaktifkan Pengiriman Email Notifikasi “Sukses Reset Password”
add_filter('wp_password_change_notification_email', 'disable_password_change_notification_email', 10, 3);
function disable_password_change_notification_email($email, $user, $blogname) {
// Mengembalikan array kosong untuk menghentikan pengiriman email
return array(
'to' => '',
'subject' => '',
'message' => '',
'headers' => '',
);
}
Multiple ID Product Dalam Link Checkout WooCommerce
function woocommerce_maybe_add_multiple_products_to_cart() {
// Make sure WC is installed, and add-to-cart qauery arg exists, and contains at least one comma.
if ( ! class_exists( 'WC_Form_Handler' ) || empty( $_REQUEST['add-to-cart'] ) || false === strpos( $_REQUEST['add-to-cart'], ',' ) ) {
return;
}
// Remove WooCommerce's hook, as it's useless (doesn't handle multiple products).
remove_action( 'wp_loaded', array( 'WC_Form_Handler', 'add_to_cart_action' ), 20 );
$product_ids = explode( ',', $_REQUEST['add-to-cart'] );
$count = count( $product_ids );
$number = 0;
foreach ( $product_ids as $product_id ) {
if ( ++$number === $count ) {
// Ok, final item, let's send it back to woocommerce's add_to_cart_action method for handling.
$_REQUEST['add-to-cart'] = $product_id;
return WC_Form_Handler::add_to_cart_action();
}
$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $product_id ) );
$was_added_to_cart = false;
$adding_to_cart = wc_get_product( $product_id );
if ( ! $adding_to_cart ) {
continue;
}
$add_to_cart_handler = apply_filters( 'woocommerce_add_to_cart_handler', $adding_to_cart->product_type, $adding_to_cart );
if ( 'simple' !== $add_to_cart_handler ) {
continue;
}
// For now, quantity applies to all products.. This could be changed easily enough, but I didn't need this feature.
$quantity = empty( $_REQUEST['quantity'] ) ? 1 : wc_stock_amount( $_REQUEST['quantity'] );
$passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );
if ( $passed_validation && false !== WC()->cart->add_to_cart( $product_id, $quantity ) ) {
wc_add_to_cart_message( array( $product_id => $quantity ), true );
}
}
}
Kupon Dalam Link Checkout WooCommerce
function webroom_woocommerce_coupon_links(){
// Bail if WooCommerce or sessions aren't available.
if (!function_exists('WC') || !WC()->session) {
return;
}
$query_var = apply_filters('woocommerce_coupon_links_query_var', 'coupon_code');
// Bail if a coupon code isn't in the query string.
if (empty($_GET[$query_var])) {
return;
}
// Set a session cookie to persist the coupon in case the cart is empty.
WC()->session->set_customer_session_cookie(true);
// Apply the coupon to the cart if necessary.
if (!WC()->cart->has_discount($_GET[$query_var])) {
// WC_Cart::add_discount() sanitizes the coupon code.
WC()->cart->add_discount($_GET[$query_var]);
}
}
add_action('wp_loaded', 'webroom_woocommerce_coupon_links', 30);
add_action('woocommerce_add_to_cart', 'webroom_woocommerce_coupon_links');
Keranjang di Halaman Checkout
*hapus huruf KWP di bagian echo do_shortcode
add_action( 'woocommerce_before_checkout_form', 'bbloomer_cart_on_checkout_page_only', 5 );
function bbloomer_cart_on_checkout_page_only() {
if ( is_wc_endpoint_url( 'order-received' ) ) return;
echo do_shortcode('[woocommerce_cartKWP]');
}
add_shortcode('woocommerce_notices', function($attrs) {
if (wc_notice_count() > 0) {
?>
<div class="woocommerce-notices-shortcode woocommerce" style="text-align: center;">
<?php wc_print_notices(); ?>
</div>
<?php
}
});
Paksa Status Pesanan “Processing” Jadi “Completed”
function gb_complete_order( $order_id )
{
$order = wc_get_order( $order_id );
if( !empty( $order ) )
{
// $payment_method = $order->get_payment_method();
$order_status = $order->get_status();
if( $order_status == 'processing' )
{
$order->update_status( 'completed' );
}
}
}
add_action( 'woocommerce_order_status_processing', 'gb_complete_order', 1 );
Agar Tombol Aksi Pesanan Hanya Tombol Selesaikan
add_filter('woocommerce_admin_order_actions','wdm_verify_product_limitation',5,2);
function wdm_verify_product_limitation( $actions, $the_order ){
if ( $the_order->has_status( array( 'complete','on-hold','cancelled','pending') ) ) {
unset($actions['processing']);
}
return $actions;
}