- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的代码显示在所有产品类型中,例如简单产品、可变产品、自定义类型......对所有人都可用的方法,但我只想将其限制为我的自定义类型。
如何将我的自定义字段类型限制为英语类(class)产品类型
add_filter( 'product_type_selector', 'english_course_wc_cpt' );
function english_course_wc_cpt( $types ){
$types[ 'wdm_custom_product' ] = __( 'English Courses' );
return $types;
}
class WC_Product_Wdm extends WC_Product{
public function __construct( $product ) {
$this->product_type = 'wdm_custom_product';
parent::__construct( $product );
// add additional functions here
}
}
add_action( 'woocommerce_product_options_general_product_data', 'english_course_custom_fields' );
function english_course_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Duration: Duration of the course
woocommerce_wp_text_input(
array(
'id' => 'duration_ec_wc_cpt',
'label' => __( 'Duration', 'woocommerce' ),
'placeholder' => 'Enter the Duration of the Course',
'desc_tip' => 'true',
'description' => __( 'Duration of the Course.', 'woocommerce' ),
'type' => 'text'
));
// Fee: Create a number field
woocommerce_wp_text_input(
array(
'id' => 'fee_ec_wc_cpt',
'label' => __( 'Fee', 'woocommerce' ),
'placeholder' => 'Enter the Fee',
'desc_tip' => 'true',
'description' => __( 'Fee of the course.', 'woocommerce' ),
'type' => 'number'
));
// Address: Create a text area field
woocommerce_wp_textarea_input(
array(
'id' => 'address_ec_wc_cpt',
'label' => __( 'Address', 'woocommerce' ),
'placeholder' => 'Enter the Address',
'desc_tip' => 'true',
'description' => __( 'Address of the course.', 'woocommerce' ),
));
echo '</div>';
}
/*
* SAVING DATA - ENGLISH COURSES (wc_cpt)
* postfix/prefix : ec_wc_cpt
*/
add_action( 'woocommerce_process_product_meta', 'save_ec_wc_cpt' );
function save_ec_wc_cpt( $post_id ){
// Save Duration field
$duration_ec_wc_cpt = $_POST['duration_ec_wc_cpt'];
if( !empty( $duration_ec_wc_cpt ) )
update_post_meta( $post_id, 'duration_ec_wc_cpt', esc_attr( $duration_ec_wc_cpt) );
// Save Fee field
$fee_ec_wc_cpt = $_POST['fee_ec_wc_cpt'];
if( !empty( $fee_ec_wc_cpt ) )
update_post_meta( $post_id, 'fee_ec_wc_cpt', esc_attr( $fee_ec_wc_cpt) );
// Save Address field
$address_ec_wc_cpt = $_POST['address_ec_wc_cpt'];
if( !empty( $fee_ec_wc_cpt ) )
update_post_meta( $post_id, 'address_ec_wc_cpt', esc_attr( $address_ec_wc_cpt) );
}
最佳答案
我认为有两种方法可以解决这个问题。 1. 将自定义字段添加到产品数据框中自己的 Pane 中。或者 2. 继续将它们添加到您正在使用的通用数据 Hook 中,然后使用 JS 隐藏它们以用于其他产品类型。
方法 1
// Creates the admin panel tab
add_action( 'woocommerce_product_write_panel_tabs', so_26338834_product_write_panel_tab' );
function product_write_panel_tab() {
echo '<li class="wdm_custom_product_tab show_if_wdm_custom_product wdm_custom_product_options"><a href="#wdm_custom_product_data">'.__( 'English Courses' ).'</a></li>';
}
// Creates the panel for selecting product options
add_action( 'woocommerce_product_write_panels', so_26338834_product_write_panel' );
function product_write_panel() {
global $post; ?>
<div id="wdm_custom_product_data" class="wdm_custom_product panel panel woocommerce_options_panel wc-metaboxes-wrapper">
<div class="options_group wdm_custom_product">
put your fields here
</div> <!-- options group -->
</div>
<?php
}
方法 2
使用 show_if_{$product_type}
类将您的输入包装在一个 div 中。我认为 WooCommerce 将为您处理隐藏/显示方面。
add_action( 'woocommerce_product_options_general_product_data', 'english_course_custom_fields' );
function english_course_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group show_if_wdm_custom_product">';
// your inputs
echo '</div>';
}
编辑:我检查了自己的代码,发现您必须编写 javascript 来隐藏/显示自己。这很容易做到,因为当产品类型输入更改时,WooCommerce 会触发自定义事件,因此我们可以编写一个触发此事件的处理程序。
// product type specific options
$( 'body' ).on( 'woocommerce-product-type-change', function( event, select_val, select ) {
if ( select_val == 'wdm_custom_product' ) {
$( '.show_if_wdm_custom_product' ).show();
} else {
$( '.show_if_wdm_custom_product' ).hide();
}
});
关于php - 如何仅为自定义产品类型定义字段 - Woo Commerce Hook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26338834/
从 AddToCart -> ShoppingCart -> CheckoutSignIn -> ShippingInfo -> ShippingMethod -> PaymentMethod ->
我在尝试访问在 Azure 中创建的新网站时出错。我无法升级。我有一个来自 Virto/admin 页面的链接,可将我引导至 http://mywebsiteurlhere.azurewebsites
我只想获取所有 ebay 产品名称及其描述,有什么办法吗?我研究了他们的 api 文档,但没有可以返回所有产品名称的 api,详细信息他们有不同的 api,用于类别搜索、个人搜索,但我需要一次获得所有
你好,我最近在今年 12 月获得了计算机科学学位,目前正在寻找网页设计/编程领域的工作。我在计算机科学相关领域没有任何工作。 无论如何,我从一家公司收到了一份我想回答的问题。 第一个问题是 “请描述您
我正在尝试升级应用程序,以便可以向多个国家/地区销售。我将所有价格以英镑存储在数据库中,不包括高达 4dp 的税,我需要计算包含税的国家货币的价格。 我是将价格乘以汇率乘以不含税价格(选项 1)还是计
在您看来,为客户进行定制软件开发,然后将该软件添加到您的其他客户可以使用的基本产品中是否常见且合乎道德? 我的看法是: 这是你们之间的契约(Contract)问题 和客户。 它经常发生(尽管可能不“常
我有一个基于订阅的网站,它与第三方系统交互以处理付款。处理新订户注册的步骤如下: 订阅者在订阅表格中输入他/她的详细信息,然后单击提交按钮。 假设指定的详细信息有效,则会在数据库中创建一条新记录来存储
基本上我想做的是设置一个类似于 PayPal 的工作流程。我创建了一个应用程序,允许我的客户接受在线捐赠,我想要做的是从该交易的顶部扣除 % 的百分比。我遇到的问题是: 授权不允许我承担支付到我的帐户
我为一家非营利组织工作,并创建了在线捐赠页面。最近,此捐赠页面已被用于通过名为 Carding 的流程验证被盗信用卡详细信息。 . 它的工作方式是,懒惰者掌握了一大堆信用详细信息,但不知道哪些数字是好
我是专业网站开发和设计的新手。我的一位客户要求我建立一个电子商务网站来销售他们的奢侈品钱包。我在 php 和 MySQL 方面有一些相当扎实的经验,但都没有专业地使用过。我还没有处理过 Session
我们有一个在不同地方使用的购物车,因此税收存储在配置文件中,目前在新西兰是 15%,因此在配置文件中我们存储 .15但是这个数字可以改变,所以我需要公式来不依赖这个值是一个特定的值! 我们还有另一个键
我想知道如何使用woocommerce在页面加载时清除购物车中的内容。 我遇到了如何通过将其添加到functions.php中来添加一个清晰的购物车按钮的方法 add_action( 'init',
我见过很多使用这种 URL 结构的网站: webapp/wcs/stores/servlet webapp/wcs/stores/OrderShippingDisplayView 它是什么应用程序?我
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 8年前关闭。 Improve this questi
客户需要能够让他们的购物车自动检索和更新至少美国的销售税表,最好是与美国有税收协定的所有国家/地区。这是一个合理的要求吗?托管解决方案很好。 最佳答案 一种选择可能是根本不征收销售税。 Amazon
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 6 年前。 Improve this ques
我的网络应用需要访问任意电子商务商店,并确定其是否具有产品数据供稿(即Google Base供稿;商店中所有产品的RSS / ATOM供稿)。另外,我需要提取此提要的位置。 到目前为止,我能想到的最好
信用卡类型可以仅根据信用卡号确定吗? 这是推荐的还是我们应该总是询问客户他们使用的信用卡类型? 我用谷歌搜索了一下,找到了这个算法:http://cuinl.tripod.com/Tips/o-1.h
我目前正计划开发一个网络应用程序,它将允许第 3 方在其上列出和销售他们自己的产品。 虽然我有开发电子商务解决方案的经验,但我个人不希望自己与实际的支付系统有任何关系(在法律上而非技术上),因此任何交
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 8年前关闭。 Improve thi
我是一名优秀的程序员,十分优秀!