我一直在尝试添加一个产品缩略图图像链接到客户最近的订单页面,我的帐户在woocommerce的产品。我已经设法获得图像缩略图到位感谢阿南德从这个问题在这里:添加产品缩略图到我的帐户-最近的订单- Woocommerce,但现在我正在努力使这个拇指成为链接到实际产品的永久链接。
所以我知道这是获取图像缩略图的代码:
<?php
// Get a list of all items that belong to the order
$products = $order->get_items();
// Loop through the items and get the product image
foreach( $products as $product ) {
$product_obj = new WC_Product( $product["product_id"] );
echo $product_obj->get_image();
}
?>
我一直在尝试把缩略图变成像这样的永久链接:
<?php
// Get a list of all items that belong to the order
$products = $order->get_items();
// Loop through the items and get the product image
foreach( $products as $product ) {
$product_obj = new WC_Product( $product["product_id"] );
echo '<a href="'.get_permalink($product_id).'"><?php echo $product_obj->get_image();?></a>';
}
?>
或者像这样:
echo '<a href="'.get_permalink($product_id).'">'echo $product_obj->get_image()'</a>';
或者:
<a href="<?php echo $url = get_permalink( $product_id ); ?>">
<?php
// Get a list of all items that belong to the order
$products = $order->get_items();
// Loop through the items and get the product image
foreach( $products as $product ) {
$product_obj = new WC_Product( $product["product_id"] );
echo $product_obj->get_image();
}
?>
但似乎不能在任何地方…div ?
这很简单,Product类有一个get_permalink
方法,您可以这样使用:
$product_obj = new WC_Product( $product["product_id"] );
$link = $product_obj->get_permalink();
echo '<a href="'. $link .'">' . $product_obj->get_image() . '</a>';
编辑
如果你想使用WordPress提供的get_permalink
,你可以这样做
echo '<a href="'.get_permalink($product_obj->id).'"><?php echo $product_obj->get_image();?></a>';
你在下面的代码中使用$product_id
,因为它没有定义在你的代码不工作的地方。你非常接近:)
echo '<a href="'.get_permalink($product_id).'"><?php echo $product_obj->get_image();?></a>';