gpt4 book ai didi

php - woocommerce/花式产品设计师结帐部分中的多个缩略图

转载 作者:行者123 更新时间:2023-12-04 01:47:29 26 4
gpt4 key购买 nike

在我的 Woocommerce 网站中,用户可以通过 Fancy product designer 设计最多 6 个不同的图像。插入。我试图在结帐页面中的购物车项目上输出这些用户的缩略图,而不是只显示一张产品图片。

Website我正在努力使这成为可能。

enter image description here (示例照片)

class-wc-cart.php

$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML( $thumbnail );
$xpath = new DOMXPath( $dom );
libxml_clear_errors();

$doc = $dom->getElementsByTagName("img")->item(1);
$src = $xpath->query(".//@src");
$srcset = $xpath->query(".//@srcset");

// custom image from customer
foreach ( $src as $s ) {
$s->nodeValue = $fpd_data['fpd_product_thumbnail'];
}
foreach ( $srcset as $s ) {
$s->nodeValue = $fpd_data['fpd_product_thumbnail'];
}
return $dom->saveXML( $doc );

我使用 foreach 循环浏览来自高级产品设计师的图像。但这就像它只是在我的结帐中列出了第一张图片。

不知道是否有可能,或者我应该在 class-wc-cart.php 中使用另一种方法woocommerce 中的文件。

class-wc-product.php
//the additional form fields
public function add_product_designer_form() {

global $post;
$product_settings = new FPD_Product_Settings($post->ID);

if( $product_settings->show_designer() ) {
?>
<input type="hidden" value="<?php echo esc_attr( $post->ID ); ?>" name="add-to-cart" />
<input type="hidden" value="" name="fpd_product" />
<input type="hidden" value="" name="fpd_product_thumbnail[]" />
<input type="hidden" value="<?php echo isset($_GET['cart_item_key']) ? $_GET['cart_item_key'] : ''; ?>" name="fpd_remove_cart_item" />
<?php

if( !fpd_get_option('fpd_wc_disable_price_calculation') )
echo '<input type="hidden" value="" name="fpd_product_price" />';

do_action('fpd_product_designer_form_end', $product_settings);
}
}

在代码中有一个函数“ after_product_designer ”,我在其中添加了一些 jquery 代码来获取应该从 FPD 发布多个 fpd_thumbnails 的输入字段。

它在 if(order.product != false)
    var values = [];

if(<?php echo fpd_get_option('fpd_cart_custom_product_thumbnail'); ?>) {
// $cartForm.find('input[name="fpd_product_thumbnail"]').val(dataURL); (OLD/Original)

$('input[name="fpd_product_thumbnail[]"]').each(function(){ // NEW
values.push($(this).val(dataURL));
});
}

最佳答案

1) 您应该向 WP.SE 询问与 WP 相关的问题

2)您的解决方案应在代码下方(添加 functions.php 并根据您的需要进行修改):

// Product thumbnail in checkout
add_filter( 'woocommerce_cart_item_thumbnail', 'product_thumbnail_in_checkout', 200, 3 );
function product_thumbnail_in_checkout( $thumbnail, $cart_item, $cart_item_key )
{
$use_product_thumb = false; //true or false
if (array_key_exists('fpd_data', $cart_item))
{
$thumbnail =""; //clear existing thumb
if ($use_product_thumb)
{
$fp = json_decode( stripslashes($cart_item['fpd_data']['fpd_product']) , true);
foreach($fp['product'] as $each)
{
$thumb = $each["thumbnail"];
$thumbnail .= '<img src="'.$thumb.'" style="width:50px; float:left; margin:5px;" />';
}
}
else{
$thumbnail = '<img src="'.$cart_item['fpd_data']['fpd_product_thumbnail'].'" style="float: left; margin: 5px; width: 200px; max-width: 550px;" />';
}
}
return $thumbnail;
}

关于php - woocommerce/花式产品设计师结帐部分中的多个缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54682635/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com