我已经使用 WooCommerce 一段时间了,但是这个问题给我带来了问题。我正在为其创建站点的客户提供培训课程和演示,而这个特定的产品(或演示)允许将几个不同的选项添加到购物车中,每个选项都有自己的价格。
因此,基本价格为零。然后有 8 种不同的演示文稿,用户可以通过其现有网站上的复选框进行选择 - 我以某种方式需要在他们的新网站上使用 WooCommerce 复制它,但我只能使用下拉菜单进行变体,据我所知它只允许一种选择。我能看到这个工作的唯一可行的方法是,如果我添加 8 个不同的下拉列表,每个下拉列表中包含所有 8 个演示文稿,然后客户选择他们想要的许多不同的演示文稿。不过这有点麻烦,并且可能会导致用户错误(例如,两次选择相同的演示文稿)。
我附上了一张我希望在 WooCommerce 中看起来像的屏幕截图,有什么办法可以实现吗?如果这是唯一的方法,我不介意使用插件。
在WooCommerce中,我$product->get_variation_attributes()用来获取产品的变体属性.此函数返回一个名称不带ID的数组.
像这样:
[pa_color-shirt] => Array
(
[0] => red
[7] => grey
[14] => yellow
)
[pa_color-sweater] => Array
(
[0] => red
[1] => green
[2] => blue
[3] => grey
[4] => yellow
[5] => pink
[6] => dark-blue
)
Run Code Online (Sandbox Code Playgroud)
对于我正在创建的AJAX商店,我还需要来自各种变体的ID.所以我可以将Id和名称附加到选择框(就像woocommerce那样).
我搜索了几天但找不到解决方案.
我创建了这段代码:
if($product->has_child()) {
$attributes = $product->get_attributes();
$variations = $product->get_available_variations();
$variationsArray = array();
foreach ($attributes as $attr => $attr_deets) {
$variationArray = array();
$attribute_label = wc_attribute_label($attr);
$variationArray["attribute_label"] = $attribute_label;
if (isset($attributes[$attr]) || isset($attributes['pa_' . $attr])) …Run Code Online (Sandbox Code Playgroud) 我已经在functions.php上有了这段代码
此代码是在每个产品变体上添加一个新字段以具有日期时间输入字段,因此当当前日期超过输入日期时,变体将自动过期。
// Add Variation Settings
add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
// Save Variation Settings
add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
//Create New fields for Variations
function variation_settings_fields( $loop, $variation_data, $variation ) {
// Text Field
woocommerce_wp_text_input(
array(
'id' => '_text_field_date_expire[' . $variation->ID . ']',
'class' => '_text_field_date_expire',
'type' => 'datetime-local',
'label' => __( 'Date of Expiration', 'woocommerce' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Expiration of Each Product Variation', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, …Run Code Online (Sandbox Code Playgroud) 我想在我的前端模板文件中显示默认的产品属性表单值和常规价格.
在var_dump下面示出了在一个阵列的选项.我需要得到[default_attributes]价值观.
<?php
global $product;
echo var_dump( $product );
// Need to get the [default_attributes] values
?>
Run Code Online (Sandbox Code Playgroud)
基于“在 WooCommerce 变量产品中每个属性值旁边显示库存状态”,我有以下代码在产品变体下拉列表中显示库存数量+库存状态以及显示的产品可用性文本:
add_filter( 'woocommerce_variation_option_name', 'customizing_variations_terms_name', 10, 1 );
function customizing_variations_terms_name( $term_name ){
if(is_admin())
return $term_name;
global $product;
$second_loop_stoped = false;
// Get available product variations
$product_variations = $product->get_available_variations();
// Iterating through each available product variation
foreach($product_variations as $variation){
$variation_id = $variation['variation_id'];
$variation_obj = new WC_Product_Variation( $variation_id );
## WOOCOMMERCE RETRO COMPATIBILITY ##
if ( version_compare( WC_VERSION, '3.0', '<' ) ) # BEFORE Version 3 (older)
{
$stock_status = $variation_obj->stock_status;
$stock_qty = intval($variation_obj->stock);
// The attributes …Run Code Online (Sandbox Code Playgroud) 例如,如果在一个文本框中,从计算机部件的材料列表中填充了许多不同的部件号,我在任何给定时间只需要一种类型的cat5电缆,如果看到两种不同的类型,则警告用户.cat5电缆部件号可以是:cat5PART#1,cat5PART#2和cat5PART#3.因此,如果看到只有一个cat5零件编号没有后顾之忧,但只要看到两种不同类型或更多,就要发出警告.对于每个变体,我可以轻松地手动将其写出三个不同的时间,但是在更大的部件列表中,它将花费更长的时间并且存在风险错误.另外,我只是想知道程序员如何处理这种类型的功能.我也不知道它叫什么,所以我不知道如何谷歌为它,尽管知道会有很多解决方案,因为这种确切的情况,所以这是令人沮丧的不得不在论坛上的人这么简单的事情.
我的代码显然不起作用的一个例子,因为它只会警告是否检测到所有三个部分而不仅仅是检测到两个部分是在下面.我假设我使用了&和|的一些变体 或者它可能是完全不同的东西?
基本上我不想在更大范围内写出来
如果包含第1部分和第2部分
如果包含第1部分和第3部分
如果包含第2部分和第3部分
谢谢.
if ((textBox2.Text.Contains("PART#1"))
&& (textBox2.Text.Contains("PART#2"))
&& (textBox2.Text.Contains("PART#3")))
{
MessageBox.Show("2 types of cat5 part numbers seen at the same time");
}
Run Code Online (Sandbox Code Playgroud) 通过WooCommerce,我使用Contact Form 7和Product Info Request插件在单个产品页面中添加表单,因为我需要一种功能,允许用户发送有关产品的查询请求(简单的联系表单).
你可以理解看到这个截图:
我的所有产品都是可变产品,具有变化(来自属性).
有没有办法检索客户选择的变体并通过联系表格7发送?
例如 :
用户选择颜色黑色和尺寸s,然后填写表格,当发送电子邮件时,除了接收经典信息(姓名,电子邮件ecc ..),我还收到所选的属性(在这种情况下black和s)
需要帮助:是否可以在WooCommerce中将用户生成的临时产品添加到购物车中?我正在尝试将非wordpress网站转移到WordPress,但是该网站已经具有一个复杂的电子商务系统,客户端不希望更改。基本上发生的是,访问者指定客户销售的产品的度量,为它添加不同的变体,然后提交后,网站根据访问者的输入生成产品的价格。添加产品将非常繁琐,因为它们有太多具有数千个变体的产品。因此,我们的解决方案是这样。除了WooCommerce,我还接受其他插件建议。我已经尝试过使用Gravity Forms,但最终由于我们的客户 添加到购物车后,当前网站必须是电子商务网站。先感谢您!
在 Woocommerce 中,我在管理区域有一份报告,记录了所售产品。网站上仅售出 5 种产品,但有些产品有 1 或 2 种变体。该报告效果很好,但忽略了变化。
我需要从订购的项目中检索属性值以准确显示数据。
我该怎么做呢?
get_variation_description() 没有按照我应用它的方式工作。
我的代码:
$order = wc_get_order( $vs);
//BEGIN NEW RETRIEVE ORDER ITEMS FROM ORDER
foreach( $order->get_items() as $item_id => $item_product ){
$ods = $item_product->get_product_id(); //Get the product ID
$odqty= $item_product->get_quantity(); //Get the product QTY
$item_name = $item_product->get_name(); //Get the product NAME
$item_variation = $item_product->get_variation_description(); //NOT WORKING
}
Run Code Online (Sandbox Code Playgroud) 好的,所以我是 Shopify 的新手,所以这可能很容易解决,我只是没有“明白”。
我想我正在使用旧主题,因为新主题似乎已经有了一个 js 文件,可以在为产品进行选项选择时更新 URL 中的变体 ID。我一直试图弄清楚,但我完全迷失了。我的主题似乎根本没有这样的东西。
我一直在尝试使用 jQuery 进行不同的事情,以从选项中获取变体 ID 值并history.pushState更改 URL 中的 ID,但这不是最好的解决方案,并且不能始终如一地工作,也不是真正的“修复”。
尽管我只想将主题更改为更新的、有效的主题,但遗憾的是,这不是一个选择,而且我知道这个主题可能很糟糕。
这是网站:https : //elizabethsuzann.com/collections/all-products
这是产品文件:
<div id="content" class="main-content">
<div id="page">
<div class="row full-width clearfix">
<div id="product-{{ product.id }}">
<div class="column medium-6 large-6 product-photos product__images left show-for-small-only">
{% include "product-toggler" %}
</div>
<div class="column medium-6 large-6 product__description right" id="product-right">
<div id="product-description">
<div class="row product__details">
<div class="column medium-9">
{% if settings.vendor %}<h3>{{ product.vendor }}</h3>{% endif %}
<h1 class="product__title medium-text-left small-text-center">{% include "product-title-replacer" …Run Code Online (Sandbox Code Playgroud) variations ×10
woocommerce ×8
wordpress ×8
php ×6
product ×5
c# ×1
contains ×1
if-statement ×1
limiting ×1
mysql ×1
options ×1
shopify ×1
stock ×1