在 Woocommerce 订单编辑页面中替换 BACS 付款方式的特定词 [英] Replace a specific word for BACS payment method in Woocommerce order edit pages

查看:70
本文介绍了在 Woocommerce 订单编辑页面中替换 BACS 付款方式的特定词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 woocommerce 的新手,通过使用 gettext 钩子可以将文本已付"替换为已放置",但我想根据一种条件显示此文本,即当客户选择电汇(bacs)时,因为没有付款收到然后只需要替换为放置的文本

Am new to woocommerce, by using gettext hook am able to replace the text "paid" with "placed" but i want to display this text based on one condition i.e when customer pick wire transfer(bacs) as there was no payment received then only text needs to replace with placed

我附上了一张图片.

推荐答案

给你

首先让我们添加更改文本功能:

function change_text($translated_text, $text, $domain)
    {

        switch ($translated_text) {

            case 'Paid on %1$s @ %2$s':

                $translated_text = __('Placed on %1$s @ %2$s', 'woocommerce');
                break;

        }

        return $translated_text;
    }

条件:

现在让我们通过使用电汇付款方式获取所有订单 ID 来创建我们的条件,如果当前帖子 ID 与我们的订单 ID 匹配,那么我们可以调用更改文本函数,如下所示:

Now let's create our condition by getting all order id with payment method wire transfer and if the current post id match our order id then we can call the changing text function as following:

add_action('admin_head', 'current_screen');
function current_screen()
{
    global $post;

    if (empty($post)) {
        return;
    } else {
        $postid = $post->ID;
    }
    $args = array(
        'payment_method' => 'bacs',
        'return' => 'ids',
    );

    $ordersid = wc_get_orders($args);

    if (!empty($postid) && in_array($postid, $ordersid)) {
        add_filter('gettext', 'change_text', 20, 3);
    }
}

这篇关于在 Woocommerce 订单编辑页面中替换 BACS 付款方式的特定词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆