if customer want to buy product from seller dokan A, only display "cod" payment gateway

WPTurbo » Snippets » if customer want to buy product from seller dokan A, only display "cod" payment gateway
0

Created with:

Visibility: 

public

Creator: mahdi

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
// Assuming you have the seller's name stored in a variable called $sellerName

// Check if the seller is "dokan plugin A" in the checkout page
add_action('woocommerce_checkout_order_processed', 'check_seller_in_checkout', 10, 1);
function check_seller_in_checkout($order_id) {
    // Get the seller ID based on the order
    $seller_id = dokan_get_seller_id_by_order($order_id);
    
    // Get the seller name using the seller ID
    $seller_name = dokan()->vendor->get($seller_id)->get_shop_name();
    
    // Check if the seller is "dokan plugin A"
    if ($seller_name === 'dokan plugin A') {
        // Display only "cod" payment gateway
        echo 'Displaying "cod" payment gateway for seller dokan plugin A.';
    }
}
?>
				

Explanation:

In this code snippet, we're using the woocommerce_checkout_order_processed action hook to check the seller in the WooCommerce Dokan checkout page. Inside the check_seller_in_checkout function, we use the dokan_get_seller_id_by_order function to retrieve the seller ID based on the order. Then, we obtain the seller name using the retrieved seller ID.

After that, we compare the seller name with "dokan plugin A" and if it matches, we display the message "Displaying 'cod' payment gateway for seller dokan plugin A" using the echo statement.

You can add this updated code snippet to your existing code.php file in order to check the seller on the WooCommerce Dokan checkout page and display the "cod" payment gateway accordingly.

Register an account to save your snippets or go Pro to get more features.