[英]How do I add a variable in the middle of an href?
I am trying to take this link below which is a search query and pull the item sku in woocommerce to be put in place of when they click the link. 我正在尝试使用下面的链接作为搜索查询,并在woocommerce中拉出sku项以代替他们单击该链接时的位置。 The code below is used to display a link in our store whenever an item is up for auction. 只要有待拍卖的物品,下面的代码就会用于在我们的商店中显示链接。 How would I add $product->get_sku() in the middle of an href? 如何在href中间添加$ product-> get_sku()? I've tried multiple ways. 我已经尝试了多种方法。 Everything I find online about variable href only shows if the entire href is a variable. 我在网上找到的有关变量href的所有内容仅显示了整个href是否为变量。 Any help is greatly appreciated. 任何帮助是极大的赞赏。
https://www.wirebids.com/search?q= "VARIABLE HERE"&open_closed=open https://www.wirebids.com/search?q= “ VARIABLE HERE”&open_closed = open
// Display Auction Link When 'auction' is in the category
function so_43372512_maybe_show_auction_link(){
if( has_term( 'auction', 'product_cat' ) ) {
echo ' <style type="text/css">
.woocommerce div.product form.cart, .woocommerce div.product p.cart {
display:none ; }
.woocommerce div.product p.price, .woocommerce div.product span.price {
display:none ; }
.woocommerce div.product p.stock {
display:none ; }
.product_meta {
margin-top:20px;
}
</style>';
echo 'Click This Button To View The Lot ';
$skusearch = $product-get_sku();
echo '<a id="auction" style="font-size:100%;color:#fff;padding:.618em 1em;border-radius:3px;background-color:#ed1c24;font-weight:700;" href="https://www.wirebids.com/search?q=' . $skusearch . '&open_closed=open" target="blank">' . __ ( 'On Auction Now!', 'your-plugin' ) . '</a>';
}
}'
I updated my code to show you what I have going on. 我更新了代码以向您展示我的情况。 Adding the variable where I have it breaks the function. 在有变量的地方添加它会破坏功能。 Feeling pretty dumb right now lol. 现在感觉很蠢。
Like this 像这样
$VARIABLENAME = $product->get_sku();
echo '<a href="https://www.wirebids.com/search?q=' . $VARIABLENAME . '&open_closed=open" style="font-size:100%;color:#fff;padding:.618em 1em;border-radius:3px;background-color:#ed1c24;" target="blank">' . __ ( 'On Auction Now!', 'your-plugin' ) . '</a>'
Or swap the quotes you are using to do 或交换您正在使用的报价
$VARIABLENAME = $product->get_sku();
echo "<a href='https://www.wirebids.com/search?q=$VARIABLENAME&open_closed=open' style='font-size:100%;color:#fff;padding:.618em 1em;border-radius:3px;background-color:#ed1c24;' target='blank'>" . __ ( 'On Auction Now!', 'your-plugin' ) . '</a>'
You can use this: 您可以使用此:
$var = $product->get_sku();
echo '<a style="font-size:100%;color:#fff;padding:.618em 1em;border-radius:3px;background-color:#ed1c24;" href="https://www.wirebids.com/search?q=' . $var . '&open_closed=open" target="blank">' . __ ( 'On Auction Now!', 'your-plugin' ) . '</a>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.