从WooCommerce admin中删除所有产品的销售价格

时间:2015-01-20 15:08:40

标签: plugins woocommerce filtering

寻找一种方法来消除woocommerce中所有产品的销售价格。管理员的视图有限,因此对于拥有超过10,000种产品的网站,手动删除销售价格可能是一项非常繁琐的任务。

可以这样做吗?

2 个答案:

答案 0 :(得分:5)

您可以批量修改产品管理员的促销价格。

或者你可以暂时将它放入你的functions.php ....加载管理员一次,然后删除。 (未经测试,因此使用风险自负)

function so_28048702_update(){
    // in theory this will grab all variations FIRST
    $args = array( 'post_type' => array( 'product','product-variation' ), 'nopaging' => true, 'sortby' => 'post_type', 'order' => 'desc' );

    $all_products = new WP_Query( $args );

    if ( $all_products->have_posts() ) : 
    while ( $all_products->have_posts() ) : 

        $all_products->the_post();
        $id = get_the_ID();
        update_post_meta( $id, '_sale_price', '' );
        $regular_price = get_post_meta( $id, '_regular_price', true );
        update_post_meta( $id, '_price', $regular_price );

        // we're on a variable product
        if( has_term( 'variable', 'product_type', $id ) ){
           variable_product_sync( $id );
        }

    endwhile;
    endif;

    wp_reset_postdata();

}
add_action( 'admin_init', 'so_28048702_update' );

答案 1 :(得分:-1)

您可以通过功能文件中的以下代码完全删除产品中的销售徽章。

remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
相关问题