在Woocommerce结帐中显示产品缩略图

时间:2018-08-17 12:37:13

标签: php wordpress woocommerce thumbnails checkout

我正在使用Woocommerce,需要在结帐表中显示产品缩略图。我发现了这个功能:

function isa_woo_cart_attributes($cart_item, $cart_item_key){ 
global $product; 
if (is_cart()){ echo "<style>#checkout_thumbnail{display:none;}</style>"; } 
$item_data = $cart_item_key['data']; 
$post = get_post($item_data->id); 
$thumb = get_the_post_thumbnail($item_data->id, array( 80, 80)); 
echo '<div id="checkout_thumbnail" style="float: left; padding-right: 10px">' . $thumb . '</div> ' . $post->post_title; } add_filter('woocommerce_cart_item_name', isa_woo_cart_attributes, 10, 2);

,这是可行的,但我还需要在购物车和cehckout表上显示产品属性(或替代产品摘录,但最好是属性)。感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

更新:您的代码中有一些错误和错误。

  

在结帐时,购物车中的商品数量紧随产品名称之后。因此,为了正确显示产品说明,需要附加代码。

请尝试以下操作:

/**
 * Sample transaction processor function.
 * @param {org.dps.track.Trade } trade - the sample transaction instance.
 * @transaction
 */
async function tradeCommodity(trade) {

    const factory = getFactory();
    trade.item.owner = trade.newOwner;
    var list = [];
    if (trade.item.items && trade.item.items.length > 0) {
        trade.item.items.forEach((asset) => {
        list.push(asset);
        });
    }  


    const assetRegistry = await getAssetRegistry('org.dps.track.Item');


    // persist the state of the current ITEM
    await assetRegistry.update(trade.item);

    for (var i = 0; i < list.length; ++i) {

         let res = await assetRegistry.get(list[i].getIdentifier());
         res.owner = factory.newRelationship('org.dps.track', 'BU', trade.newOwner.getIdentifier());
         // persist the state of the ITEM with new owner as a relationship
         await assetRegistry.update(res);
    }

}

代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。


在购物车页面上:

enter image description here

在结帐页面上

enter image description here