Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更名为Woocommerce“;下订单”;按钮,如果订单总数为0_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 更名为Woocommerce“;下订单”;按钮,如果订单总数为0

Php 更名为Woocommerce“;下订单”;按钮,如果订单总数为0,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,如果订单总数为0,我想更改下订单文本的文本,使其与自由订单不同 我试过这个 add_filter( 'woocommerce_order_button_text', 'misha_custom_button_text' );   function misha_custom_button_text( $button_text ) { return 'Submit'; // new text is here } 我希望我能找到解决办法 致以最诚挚的问候请将您的功能替换为以下内容,如果它适合

如果订单总数为0,我想更改下订单文本的文本,使其与自由订单不同

我试过这个

add_filter( 'woocommerce_order_button_text', 'misha_custom_button_text' );
 
function misha_custom_button_text( $button_text ) {
   return 'Submit'; // new text is here 
}
我希望我能找到解决办法
致以最诚挚的问候

请将您的功能替换为以下内容,如果它适合您,请再试一次

function misha_custom_button_text($button_text) {
    $total = WC()->cart->total;

    if ($total == 0) {
        $button_text = "Submit";
    }
    return $button_text;
}
您可以从
WC()->cart->cart\u contents\u total
获取购物车总计,并根据需要应用条件


希望这对您有所帮助。

用下面的函数替换您的函数,如果它适合您,请尝试一次

function misha_custom_button_text($button_text) {
    $total = WC()->cart->total;

    if ($total == 0) {
        $button_text = "Submit";
    }
    return $button_text;
}
您可以从
WC()->cart->cart\u contents\u total
获取购物车总计,并根据需要应用条件


希望这对您有所帮助。

用此代码替换您的代码

add_filter('woocommerce_order_button_text', 'misha_custom_button_text', 9999);

function misha_custom_button_text($button_text) {
    global $woocommerce;
    $total = $woocommerce->cart->total;
    if ($total == 0) {
        $button_text = "Free Orders";
    }
    return $button_text;
}

用此代码替换您的代码

add_filter('woocommerce_order_button_text', 'misha_custom_button_text', 9999);

function misha_custom_button_text($button_text) {
    global $woocommerce;
    $total = $woocommerce->cart->total;
    if ($total == 0) {
        $button_text = "Free Orders";
    }
    return $button_text;
}

好的,非常感谢,我会测试它,所以它是购物车总数而不是订单总数,对吗?是的,在下订单之后,你会得到订单总数,在你得到购物车总数之前。非常感谢你的回答,它是有效的,但是你能告诉我哪一个更好你的答案还是这个答案:我认为@Praveen Kumar答案更好。WC()和global$woocommerce之间没有区别,但区别在于:$woocommerce->cart->total&WC()->cart->cart\u contents\u total。因此,你可以检查这个答案。是的,我也更新了我的答案,这样你会更清楚。好的,非常感谢你,我会测试它,所以它是购物车总数而不是订单总数,对吗?是的,你下订单后会得到订单总数,在你得到购物车总数之前。非常感谢你的回答,但你能告诉我你的答案和这个答案哪个更好吗:我认为@Praveen Kumar答案更好。WC()和global$woocommerce之间没有区别,但区别在于:$woocommerce->cart->total&WC()->cart->cart\u contents\u total。为此,你可以检查这个答案。是的,我也更新了我的答案,这样你会更清楚。非常感谢你的答案,它是有效的,但是你能告诉我你的答案和这个答案哪个更好吗:两个答案的逻辑相同,但这是Woocommerce根据插件的标准代码。非常感谢你的回答,它是有效的,但是你能告诉我你的答案和这个答案哪个更好吗:两个答案的逻辑是相同的,但这是标准代码。