Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function vendor_payment_methods_shortcode() {
- global $product;
- $vendor_id = get_post_field('post_author', $product->get_id());
- if(!$vendor_id) return '';
- $vendor_payment_methods = get_user_meta($vendor_id, 'wcfm_preferred_customer_payment', true);
- if (WC()->payment_gateways()) {
- $payment_gateways = WC()->payment_gateways->get_available_payment_gateways();
- } else {
- $payment_gateways = [];
- }
- if (!empty($payment_gateways) && !empty($vendor_payment_methods) ) {
- $vendor_payment_methods_keys = array_keys($vendor_payment_methods);
- $vendor_payment_method_names = [];
- foreach($vendor_payment_methods_keys as $method) {
- $vendor_payment_method_names[] = $payment_gateways[$method]->title ?? $method;
- }
- $payment_methods_text = implode(', ', $vendor_payment_method_names);
- return 'Payment methods available for this vendor: ' . $payment_methods_text;
- } else {
- return 'No payment methods available for this vendor.';
- }
- }
- add_shortcode('vendor_payment_methods', 'vendor_payment_methods_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement