- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
现在我正在使用下面的代码
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Custom fields will be created here...
// Product Select
?>
<p class="form-field product_field_type">
<label for="product_field_type"><?php _e( 'Product Select', 'woocommerce' ); ?></label>
<select style="width:100%" id="product_field_type" name="product_field_type[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>">
<?php
$product_field_type_ids = get_post_meta( $post->ID, '_product_field_type_ids', true );
$product_ids = ! empty( $product_field_type_ids ) ? array_map( 'absint', $product_field_type_ids ) : null;
if ( $product_ids ) {
foreach ( $product_ids as $product_id ) {
$product = get_product( $product_id );
$product_name = woocommerce_get_formatted_product_name( $product );
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>';
}
}
?>
</select> <img class="help_tip" data-tip='<?php _e( 'Your description here', 'woocommerce' ) ?>' src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png" height="16" width="16" />
</p>
<?php
echo '</div>';
}
最佳答案
我最近试图为我的一个客户找出同样的问题。我最初使用相同的教程在后端为他添加自定义产品搜索输入字段,当我们将他更新到 WooCommerce 2.5+ 时,它就崩溃了。
将产品搜索小部件/字段添加到后端:
?>
<p class="form-field product_field_type">
<label for="product_field_type_ids"><?php _e( 'Component Products:', 'woocommerce' ); ?></label>
<input type="hidden" class="wc-product-search" style="width: 50%;" id="product_field_type_ids" name="product_field_type_ids" data-placeholder="<?php esc_attr_e( 'Search for a product…', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products" data-multiple="true" data-exclude="<?php echo intval( $post->ID ); ?>" data-selected="<?php
$product_ids = array_filter( array_map( 'absint', (array) get_post_meta( $post->ID, '_product_field_type_ids', true ) ) );
$json_ids = array();
foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id );
if ( is_object( $product ) ) {
$json_ids[ $product_id ] = wp_kses_post( html_entity_decode( $product->get_formatted_name(), ENT_QUOTES, get_bloginfo( 'charset' ) ) );
}
}
echo esc_attr( json_encode( $json_ids ) );
?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" /> <?php echo wc_help_tip( __( 'Select component parts to display on the product page.', 'woocommerce' ) ); ?>
</p>
<?php
$my_product_ids = isset( $_POST['product_field_type_ids'] ) ? array_filter( array_map( 'intval', explode( ',', $_POST['product_field_type_ids'] ) ) ) : array();
update_post_meta( $post_id, '_product_field_type_ids', $my_product_ids );
global $post;
$items = get_post_meta($post->ID, '_product_field_type_ids', true);
if (! empty($items)) {
foreach ( $items as $product_id ) {
echo '<div class="productLink"><a href="'.get_permalink($product_id).'">'.get_the_title($product_id).'</a></div>';
}
}
关于wordpress - 在woo-commerce产品页面添加产品搜索字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30973651/
我正在尝试在面包屑上方添加标题。我的问题是为什么 WooCommerce 条件在 template_redirect 上效果更好但不要在 init 上工作.例如: /** Woo General In
如何以编程方式设置隐藏在 woo-commerce WordPress 中的目录可见性? 就像这里提到的: https://docs.woothemes.com/document/catalog-vi
我的代码显示在所有产品类型中,例如简单产品、可变产品、自定义类型......对所有人都可用的方法,但我只想将其限制为我的自定义类型。 如何将我的自定义字段类型限制为英语类(class)产品类型 add
我正在寻找一种方法来重定向我的批发用户。 我为批发设置 woo-commerce 的方法是根据我命名为“批发”的 wordpress 用户角色将用户分配给批发。 我想保留普通用户的重定向而不做任何更改
我正在使用 Add a custom select field with collection times in WooCommerce checkout创建集合下拉列表 我的问题是如何让我的收集时间
我在将变体下拉列表转换为支持 woocommerce 的网站的单选按钮时遇到问题。我已经尝试找到答案 here但我似乎无法使这个解决方案发挥作用。我还尝试编辑variable.php 文件中的代码。
我想将销售价格移动到实际价格之下以进行变化,我设法为产品摘要部分执行此操作但无法找到任何变化过滤器。 请看下图。 我已经尝试过此代码但没有成功,我的代码适用于 Summery 部分 add_filte
我想修改 woo-commerce 特色产品小部件的 HTML 代码。问题是我在模板文件夹/插件文件夹中找不到它。 有人知道如何修改woo-commerce的特色产品小部件吗? 最佳答案 这是通过位于
我正在使用 woo canvas 主题开发网站。我想为移动响应布局添加自定义 css。Canvas 是响应式的,但我想添加自定义 css 以更改字体大小等。我正在使用以下代码在我的 Canvas 子主
如何在 Woo Canvas 中为我的菜单下拉菜单设置自定义宽度,使其与主选项卡的宽度相匹配?我的测试站点在 http://www.fopm.co.uk/eds 不正确的标签是打印服务和联系我们 谢谢
在我的 WooCommerce 网站中,我正在使用此插件 WooCommerce Order Cancel for Customers允许客户根据付款类型和时间延迟取消订单。但是取消按钮只出现在“wo
这是我到目前为止所拥有的: Scanner scan = new Scanner(System.in); String str = scan.nextLine(); int x
我正在尝试建立一个带有 woo commerce 的网上商店,这看起来是一个非常不错且易于使用的系统。但我真的遇到了一些麻烦。很多时候代码中有这样的函数:do_action( 'woocommerce
价格与名称(标题)对齐的问题 CSS 代码 .mgrt-product-title .price { padding-left: 749px; font-weight: bold; color:
我正在使用 Woo Testimonials Wordpress 插件来创建推荐信。不幸的是,在最近的更新之后,这不再正常工作。每个推荐书的反引号都丢失了,作者的引文与引文重叠。 有人知道如何解决这个
我正在实现一个“POST”api,用于通过 woo-commerce 创建订单: POST http://www.url.in/wp-json/wc/v1/orders 我还为其使用了外部库 Oaut
我有WordPress网站www.kampengCourse.id来选择语言课程。我想展示一下有多少人看过特定的产品。使用帖子视图计数器插件,它可以在主页和博客页面上显示帖子视图,但在商务产品页面上不
我是一名优秀的程序员,十分优秀!