custom-fields 相关问题

WordPress自定义字段:作者输入的帖子元数据

在 WooCommerce 单一产品页面中有条件地显示自定义字段值

我正在开发一个 Woocommerce 网站,该网站要求其某些产品在简短描述下和购物车之前包含额外的信息“产品功能”。 我创建了一个选项卡...

回答 1 投票 0

使用 WC Kalkulator 产品字段值更新 WooCommerce 购物车项目属性

在 WooCommerce 中,我将 WC Kalkulator 插件用于一个简单的产品 (ID 4692)。问题是,这个简单的产品只有静态重量和尺寸值,这些值被拉入每个购物车项目

回答 1 投票 0

使用产品自定义字段值更新 WooCommerce 购物车项目属性

在 WooCommerce 中,我将 WC Kalkulator 插件用于一个简单的产品 (ID 4692)。问题是,这个简单的产品只有静态重量和尺寸值,这些值被拉入每个购物车项目

回答 1 投票 0

如何使用 WC Kalkulator 中的字段值将唯一的运输重量、长度、宽度和高度应用于添加到 woocom 购物车的每个实例?

我已经安装了插件 WC Kalkulator 并可与我的 woocommerce 网站配合使用。它以简单的产品 ID 4692 运行。问题是,简单的产品只有静态重量和尺寸 va...

回答 1 投票 0

定义的产品自定义字段值替换 WooCommerce 循环上的价格[已关闭]

在我的 WooCommerce 产品上,我想用产品型号参考自定义字段(例如:#AB2568B)替换产品价格。如何显示型号参考而不是价格?请帮忙。

回答 1 投票 0

在 woocommerce_get_price_html 挂钩中的价格后添加多语言文本

我正在构建一个 WooCommerce 网站并对其进行自定义,从互联网库复制和粘贴代码。 我已设法在 woocommerce 产品中添加“自定义价格和自定义文本”,这样它们就可以

回答 1 投票 0

在 Woocommerce 中设置可变产品的最小显示单位价格

我正在 WooCommerce 中建立一个网上商店来销售医用手套。它们按单位、按盒或按托盘出售。当您按盒或托盘购买时,您会得到较低的单价。 我一直在玩...

回答 1 投票 0

在 Wovcommerce 中添加到购物车之前可更改产品价格的附加自定义按钮

在 Woocommerce 中,我在后端为我的产品添加了一个额外的价格字段“bestprice”。 所以现在我有尽可能的价格设置: 正常价格(例如 100 美元), 销售价格(未设定) (和)

回答 1 投票 0

设置 WooCommerce 产品的价格范围,无需设置变量

在 woocommerce 中,我希望能够为我的简单产品设定价格范围,而无需设置可变产品,因为我不需要它。 请参阅以下链接:https://www.tnbloom.com.au/product/

回答 1 投票 0

这些帖子在Wordpress 中是如何设置的?

我正在审核一个 WordPress 网站 - 了解它当前的设置方式以及可以进行哪些改进。我注意到“播客”、“课程”和“目录”没有被创建为...

回答 1 投票 0

基于自定义字段的 WooCommerce 产品变化价格

我有可变的产品,我添加了如下自定义字段: 函数 ab_preorder_variation_fields( $loop, $variation_data, $variation ) { 回声' 我有可变的产品,我添加了这样的自定义字段: function ab_preorder_variation_fields( $loop, $variation_data, $variation ) { echo '<div class="options_group form-row form-row-full">'; // Is Preordable woocommerce_wp_checkbox( array( 'id' => '_ab_preorder_checkbox[' . $variation->ID . ']', 'wrapper_class' => 'show_if_simple', 'label' => __(' Disponible à la précommande', 'woocommerce' ), 'description' => __( 'Disponible à la précommande', 'woocommerce' ), 'desc_tip' => true, 'value' => get_post_meta( $variation->ID, '_ab_preorder_checkbox', true ) ) ); // Custom Preorder Price woocommerce_wp_text_input( array( 'id' => '_ab_preorder_custom_price[' . $variation->ID . ']', 'label' => __( 'Prix à la précommande', 'woocommerce' ), 'placeholder' => '', 'desc_tip' => true, 'description' => __( "Prix à la précommande", 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array( 'step' => 'any', 'min' => '0' ), 'value' => get_post_meta( $variation->ID, '_ab_preorder_custom_price', true ) ) ); // Date de livraison estimée woocommerce_wp_text_input( array( 'id' => '_ab_preorder_estimated_date[' . $variation->ID . ']', 'label' => __( 'Date de livraison estimé', 'woocommerce' ), 'placeholder' => '24/09/2021', 'desc_tip' => true, 'description' => __( "Date de livraison estimé", "woocommerce" ), 'value' => get_post_meta( $variation->ID, '_ab_preorder_estimated_date', true ) ) ); echo '</div>'; } add_action( 'woocommerce_product_after_variable_attributes', 'ab_preorder_variation_fields', 10, 3 ); // After all Variation fields function ab_preorder_variation_fields_saving( $post_id ){ // Is Preordable $woocommerce_text_field = $_POST['_ab_preorder_checkbox'][ $post_id ]; update_post_meta( $post_id, '_ab_preorder_checkbox', esc_attr( $woocommerce_text_field ) ); // Custom Preorder Price $woocommerce_text_field = $_POST['_ab_preorder_custom_price'][ $post_id ]; update_post_meta( $post_id, '_ab_preorder_custom_price', esc_attr( $woocommerce_text_field ) ); // Date de livraison estimée $woocommerce_text_field = $_POST['_ab_preorder_estimated_date'][ $post_id ]; update_post_meta( $post_id, '_ab_preorder_estimated_date', esc_attr( $woocommerce_text_field ) ); } 这是 WP Admin 中的结果: 这就是我想做的: 当客户选择变体时,我想要:如果变体库存数量为 0 并且选中了 _ab_preorder_checkbox 复选框,我想将产品价格设置为 100。 我尝试使用下面的代码,但它不起作用:/ function action_woocommerce_before_calculate_totals( $cart_object) { $cart_items = $cart_object->cart_contents; if ( ! empty( $cart_items ) ) { $price = 100; foreach ( $cart_items as $key => $value ) { if($value['data']['_ab_preorder_checkbox']=="yes") $value['data']->set_price( $price ); } } }; add_action( 'woocommerce_before_calculate_totals', 'action_woocommerce_before_calculate_totals', 10, 2 ); 有人可以帮我吗? 问候, 由于 woocommerce 不允许购买零库存的产品,因此您需要为相关产品设置“允许缺货”选项。 我重新审视了你的代码(特别是你的第二个函数)。 挂钩 woocommerce_before_calculate_totals 在您的情况下不方便。最好在产品上设置延期交货自定义价格。 以下内容将在启用复选框时设置变体的延期交货价格,并将其显示在相关变体上以及预计交货日期: // Admin Variation custom fields add_action( 'woocommerce_product_after_variable_attributes', 'ab_preorder_variation_fields', 10, 3 ); function ab_preorder_variation_fields( $loop, $variation_data, $variation ) { echo '<div class="options_group form-row form-row-full">'; // Is Preordable woocommerce_wp_checkbox( array( 'id' => '_ab_preorder_checkbox['.$loop.']', 'wrapper_class' => 'show_if_simple', 'label' => __(' Disponible à la précommande', 'woocommerce' ), 'description' => __( 'Disponible à la précommande', 'woocommerce' ), 'desc_tip' => true, 'value' => get_post_meta( $variation->ID, '_ab_preorder_checkbox', true ) ) ); // Custom Preorder Price woocommerce_wp_text_input( array( 'id' => '_ab_preorder_custom_price['.$loop.']', 'label' => __( 'Prix à la précommande', 'woocommerce' ), 'placeholder' => '', 'desc_tip' => true, 'description' => __( "Prix à la précommande", 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array( 'step' => 'any', 'min' => '0' ), 'value' => get_post_meta( $variation->ID, '_ab_preorder_custom_price', true ) ) ); // Date de livraison estimée woocommerce_wp_text_input( array( 'id' => '_ab_preorder_estimated_date['.$loop.']', 'label' => __( 'Date de livraison estimé', 'woocommerce' ), 'desc_tip' => true, 'description' => __( "Date de livraison estimé", "woocommerce" ), 'type' => 'date', 'value' => get_post_meta( $variation->ID, '_ab_preorder_estimated_date', true ) ) ); echo '</div>'; } // Save admin Variations custom fields values add_action( 'woocommerce_admin_process_variation_object', 'ab_preorder_variation_fields_saving', 10, 2 ); function ab_preorder_variation_fields_saving( $variation, $loop ) { if( isset($_POST['_ab_preorder_checkbox'][$loop]) ) { $variation->update_meta_data( '_ab_preorder_checkbox', esc_attr($_POST['_ab_preorder_checkbox'][$loop]) ); } if( isset($_POST['_ab_preorder_custom_price'][$loop]) ) { $variation->update_meta_data( '_ab_preorder_custom_price', esc_attr($_POST['_ab_preorder_custom_price'][$loop]) ); } if( isset($_POST['_ab_preorder_estimated_date'][$loop]) ) { $variation->update_meta_data( '_ab_preorder_estimated_date', esc_attr($_POST['_ab_preorder_estimated_date'][$loop]) ); } } // Set the variation backorder price add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2 ); add_filter('woocommerce_product_variation_get_price', 'custom_price', 99, 2 ); function custom_price( $price, $product ) { if ( $product->get_stock_quantity() == 0 && $product->get_meta('_ab_preorder_checkbox') === 'yes' ) { $backorder_price = $product->get_meta('_ab_preorder_custom_price'); if( $backorder_price > 0 ) { $price = (float) $backorder_price; } } return $price; } // Display prefixed backorder price and estimated delivery on single product pages add_filter( 'woocommerce_available_variation', 'ab_available_variation_custom_field', 10, 3 ); function ab_available_variation_custom_field( $variation_data, $product, $variation ) { if ( $variation->get_stock_quantity() == 0 && $variation->get_meta('_ab_preorder_checkbox') === 'yes' ) { if ( $estimated_delivery_date = $variation->get_meta('_ab_preorder_estimated_date') ) { // Display estimated delivery date $variation_data['availability_html'] .= sprintf( '<p class="stock date-precommande">%s : %s</p>', __("Date de livraison estimée (précommande)", "woocommerce"), $estimated_delivery_date ); } // Displayed prefixed formatted price $variation_data['price_html'] = '<span class="price-prefix">'.__("Prix à la précommande", "") .'<span> : ' . wc_price( $variation_data['display_price'] ); } return $variation_data; } // Display on estimated delivery date on cart and checkout add_filter( 'woocommerce_get_item_data', 'display_acf_on_cart_and_checkout', 10, 2 ); function display_acf_on_cart_and_checkout( $cart_data, $cart_item ) { if ( $cart_item['variation_id'] > 0 && $cart_item['data']->get_stock_quantity() == 0 && $cart_item['data']->get_meta('_ab_preorder_checkbox') === 'yes' ) { if ( $estimated_delivery_date = $cart_item['data']->get_meta('_ab_preorder_estimated_date') ) { $custom_items[] = array( "name" => __("Date de livraison estimée", "woocommerce"), "value" => $estimated_delivery_date ); } } return $custom_items; } 代码位于活动子主题(或活动主题)的functions.php 文件中。已测试并有效。

回答 1 投票 0

购物车商品价格计算,基于 Woocommerce 中选择的“天”自定义字段

在 Woocommerce 中,我根据以下线程代码使用自定义字段来计算产品的价格:在 Woocommerce 3 中将产品自定义字段显示为订单项目。 // 在唱歌之前添加自定义字段...

回答 1 投票 0

根据 WooCommerce 中的自定义字段使用不同显示的产品属性标签名称

在 WooCommerce 中,我定义了添加/定义了一些产品属性及其名称,并且我编写了一些代码,这些代码应该允许我在可变产品级别定义替代属性标签名称。 S...

回答 1 投票 0

向 WooCommerce 管理优惠券设置添加自定义多选字段

在 Woocommerce 后端“添加 cupon”部分中,我想创建一个名为“免费产品”的额外自定义字段,其中有 2 个选项“是和否”。 如果是,那么是多产品

回答 1 投票 0

如何在 Wordpress Woocommerce 优惠券后端创建自定义字段

在 Woocommerce 后端“添加 cupon”部分中,我想创建一个名为“免费产品”的额外自定义字段,其中有 2 个选项“是和否”。 如果是,那么是多产品

回答 1 投票 0

无法访问元json中的自定义字段

我有一本自定义帖子类型的书,在它的参数中我有 'show_in_rest' => 真, 现在我想向其中添加一个自定义字段,如下所示: add_action( 'init', 'add_to_rest_test' ); 函数 add_to_rest_t...

回答 1 投票 0

为一篇文章显示多个自定义字段

我有两个“自定义字段”分配给我的帖子。这两个“自定义字段”具有相同的名称,但“值”不同。目前,我下面的代码仅显示其中一个链接。我正在尝试...

回答 1 投票 0

如何在Typescript中正确使用useField(Formik)?

当我尝试从我的传递所有道具(类型、占位符、类名等)时出现错误,我该如何修复它? ** 这是我的代码:** 当我尝试从我的<MyTextInput />传递所有道具(类型、占位符、类名等)时出现错误,我该如何修复它? ** 这是我的代码:** <MyTextInput label="Password:" name="password" placeholder="Enter your password" className="text-pink-600" /> 这是我的自定义输入组件: import { FieldHookConfig, useField } from 'formik'; import React from 'react'; interface IFieldProps { label?: string; } const MyTextInput: React.FC<IFieldProps & FieldHookConfig<string>> = ({ label, ...props }) => { const { name } = props; const [field, meta] = useField(props); // console.log({ field, meta, others }); return ( <div className="flex flex-col"> <label htmlFor={name}>{label}</label> <input id={name} type="text" {...field} {...props} /> // error here... </div> ); }; export default MyTextInput; ** 这是错误:** Type '{ ref?: LegacyRef<HTMLInputElement> | undefined; key?: Key | null | undefined; accept?: string | undefined; alt?: string | undefined; autoComplete?: HTMLInputAutoCompleteAttribute | undefined; ... 295 more ...; innerRef?: ((instance: any) => void) | undefined; } | { ...; } | { ...; }' is not assignable to type 'DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>'. Type '{ ref?: LegacyRef<HTMLSelectElement> | undefined; key?: Key | null | undefined; autoComplete?: string | undefined; disabled?: boolean | undefined; ... 275 more ...; checked?: boolean | undefined; }' is not assignable to type 'DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>'. Type '{ ref?: LegacyRef<HTMLSelectElement> | undefined; key?: Key | null | undefined; autoComplete?: string | undefined; disabled?: boolean | undefined; ... 275 more ...; checked?: boolean | undefined; }' is not assignable to type 'ClassAttributes<HTMLInputElement>'. Types of property 'ref' are incompatible. Type 'LegacyRef<HTMLSelectElement> | undefined' is not assignable to type 'LegacyRef<HTMLInputElement> | undefined'. Type '(instance: HTMLSelectElement | null) => void' is not assignable to type 'LegacyRef<HTMLInputElement> | undefined'. Type '(instance: HTMLSelectElement | null) => void' is not assignable to type '(instance: HTMLInputElement | null) => void'. Types of parameters 'instance' and 'instance' are incompatible. Type 'HTMLInputElement | null' is not assignable to type 'HTMLSelectElement | null'. Type 'HTMLInputElement' is missing the following properties from type 'HTMLSelectElement': length, options, selectedIndex, selectedOptions, and 4 more.ts(2322) (property) JSX.IntrinsicElements.input: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> 我不想这样做:<input {...field} placeholder={props.placeholder} type={props.type} /> 我认为问题源于FieldHookConfig的定义: export type FieldHookConfig<T> = GenericFieldHTMLAttributes & FieldConfig<T>; 其中 GenericFieldHTMLAttributes 定义为 export type GenericFieldHTMLAttributes = | JSX.IntrinsicElements['input'] | JSX.IntrinsicElements['select'] | JSX.IntrinsicElements['textarea']; 基本上,TypeScript 会警告您,由于您使用的是 FieldHookConfig,因此您收到的属性总是有可能是 select 或 textarea 属性,这些属性与 input 不兼容。 我认为解决这个问题的最好方法是: import { FieldConfig, useField } from 'formik'; import React from 'react'; interface IFieldProps { label?: string; } const MyTextInput: React.FC<IFieldProps & FieldConfig<string> & JSX.IntrinsicElements['input']> = ({ label, ...props }) => { const { name } = props; const [field, meta] = useField(props); // console.log({ field, meta, others }); return ( <div className="flex flex-col"> <label htmlFor={name}>{label}</label> <input id={name} type="text" {...field} {...props} /> </div> ); }; export default MyTextInput; this should 将类型缩小为仅访问 input 属性。

回答 1 投票 0

在发送信封之前需要帮助使用动态数据预填充 DocuSign 模板文档字段

我目前正在开发一个项目,需要在发送信封之前用动态数据预填充 DocuSign 模板文档字段。我尝试过多种方法但都没有成功...

回答 1 投票 0

仅显示特定 WooCommerce 产品类别的额外产品字段

我在产品订单上添加了一个额外的字段,以便在订购特定产品时允许自定义注释: // 在单个产品页面显示自定义字段 函数 d_extra_product_field(){ $v...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.