我真的试图在这里搜索其他相关主题,但没有成功。 我有woocommerce网站,当我按属性(型号, 我得到的产品都有变化,到目前为止一切都很好
但是,我需要产品将默认变量设置为所选的过滤器,因为每个变量都有不同的图片,当有人在我的网站上按属性过滤时,他希望看到所有产品上的特定模型。
我正在销售的情况下,每种产品都适合大约11种不同的设备,并且几乎每个产品都有不同的产品形象。
感谢帮手。
再次,我在这里尝试寻找其他主题,并对我的子主题函数php文件的许多功能进行了修改,但没有一个对我有帮助。
编辑:为清楚起见,我已经具有“模型属性”的默认值, 但是,必须更改默认属性值(对于所有显示的产品)每次用户过滤到不同属性值(更改型号) 那就是我想做的事情:(this is the source before i changed the code)
add_filter( 'woocommerce_product_get_default_attributes', 'filtering_product_get_default_attributes', 10, 2 );
function filtering_product_get_default_attributes( $default_attributes, $product ){
// We EXIT if it's not a variable product
if( ! $product->is_type('variable') ) return $default_attributes;
## --- YOUR SETTINGS (below) --- ##
// The desired product attribute taxonomy (always start with "pa_")
$taxonomy = 'pa_model';
## --- The code --- ##
// Get the attribute used for filer from URL
$Model = $_GET['pa_model'];
$default_attribute = $product->get_variation_default_attribute( $taxonomy );
// We EXIT if define Product Attribute is not set for variation usage
if( empty( $default_attribute ) ) return $default_attributes;
$default_attributes[$taxonomy] = $Model;
return $default_attributes; // Always return the values in a filter hook
}
编辑: 我将再次解释该问题: 在我可以看到产品网格的商店页面上,我按属性过滤产品结果时,设置为变体的图像不会改变 。 而在单个产品页面上,它的效果很好(更改版本也会更改产品图片)
再次-感谢您的帮助