小编Har*_*rry的帖子

使用 woocommerce_product_get_price 挂钩结帐价格问题

我需要将 Woocommerce 前端中每个产品的价格加倍。为此,我使用了以下代码:

add_filter( 'woocommerce_product_get_price', 'double_price', 10, 2 );
function double_price( $price, $product ){
    return $price*2;
}
Run Code Online (Sandbox Code Playgroud)

但是使用此代码有错误。结帐页面价格不正确。例如产品原价是10。我们通过这个代码将价格加倍。所以现在产品价格是20。当我将此产品添加到购物车时,购物车和结帐页面的价格是 40。这意味着这种乘法发生在两次。

请帮助解决这个问题。

php wordpress checkout cart woocommerce

3
推荐指数
1
解决办法
4975
查看次数

交换功能在Golang中不起作用

实际上我只是开始学习golang。一开始,我认为=:=相同。但是后来我知道两者之间有些区别。

我在golnag中学习了交换功能

import "fmt"

func swap(x, y string) (string, string) {
    return y, x
}

func main() {
    a, b := swap("hello", "world")
    fmt.Println(a, b)
}
Run Code Online (Sandbox Code Playgroud)

但是当我使用var此功能重写此功能时不起作用

package main

import "fmt"

func swap(x, y string) (string, string) {
    return y, x
}

func main() {
   var a, b string
    a ="hello"
    b="world"
     swap(a, b)
    fmt.Println(a, b)
}
Run Code Online (Sandbox Code Playgroud)

这个程序有什么错误?

go

0
推荐指数
1
解决办法
1100
查看次数

如何在golang中只显示多值结果的一个输出

最近,我研究了Golang可以为函数返回多个结果.所以我写了一个函数:

func store(x, y int) (int, int) {
    return x + y, x - y
}
Run Code Online (Sandbox Code Playgroud)

在此之后我写下面的代码:

func main() {
    a, b := store(6, 4)
    fmt.Println(a, b)
} 
Run Code Online (Sandbox Code Playgroud)

结果是:

10 2

这工作正常.

但是如果我只想打印一个,那么我该怎么办呢?

func main() {
    a, b := store(6, 4)
    fmt.Println(a)
}
Run Code Online (Sandbox Code Playgroud)

结果:

tmp/sandbox683412938/main.go:12:19:b声明并且未使用

另外,为什么我不能写:

func main() {
    a := store(6, 4) // ???
    fmt.Println(a)
}
Run Code Online (Sandbox Code Playgroud)

请指导我.

function return-value go

-2
推荐指数
1
解决办法
170
查看次数

标签 统计

go ×2

cart ×1

checkout ×1

function ×1

php ×1

return-value ×1

woocommerce ×1

wordpress ×1