相关疑难解决方法(0)

在单个产品页面上添加一个复选框,这会在Woocommerce中增加额外的费用

在woocommerce中,我使用以下代码在管理产品编辑页面上显示输入文本字段,这使我可以向该产品添加附加定价选项:

add_action( 'woocommerce_product_options_pricing', 'wc_cost_product_field' );
function wc_cost_product_field() {
    woocommerce_wp_text_input( array( 'id' => 'repair_price', 'class' => 'wc_input_price short', 'label' => __( 'Repair Cost', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')' ) );
}

add_action( 'save_post', 'wc_cost_save_product' );
function wc_cost_save_product( $product_id ) {

     // stop the quick edit interferring as this will stop it saving properly, when a user uses quick edit feature
     if (wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce'))
        return;

    // If this is a auto save do nothing, we only save when …
Run Code Online (Sandbox Code Playgroud)

php wordpress option woocommerce price

3
推荐指数
1
解决办法
1729
查看次数

标签 统计

option ×1

php ×1

price ×1

woocommerce ×1

wordpress ×1