Woocommerce - 无法删除产品差异化(Woocommerce - Cannot dele

2019-10-19 16:57发布

使用WooCommerce 2.6.1

我不能删除产品变化的变量产品:成绩仍然是在Ajax调用后的数据库。 这似乎Ajax调用不经过:把error_log中(的print_r( 'remove_variation',真)); 不输出任何东西(类-WC-ajax.php线387)。 该行动是在类的构造函数中添加。 该功能公共职能remove_variation()只是不叫。

有没有人有同样的问题,并找到了一种方法,使工作?

Answer 1:

/**
* Trash a variation, don't delete it permanently.
*
* This is hooked to
* Hijack WooCommerce's WC_AJAX::remove_variation() "Delete Variation" Trash a variation if it is a subscription variation via ajax function
*/
public static function remove_variations() {

if ( isset( $_POST['variation_id'] ) ) { // removing single variation
error_log("here3");

check_ajax_referer( 'delete-variation', 'security' );
$variation_ids = array( $_POST['variation_id'] );
error_log($_POST['variation_id']);

} else { // removing multiple variations
error_log("here4");

check_ajax_referer( 'delete-variations', 'security' );
$variation_ids = (array) $_POST['variation_ids'];

}

foreach ( $variation_ids as $variation_id ) {

$variation_post = get_post( $variation_id );
error_log(print_r($variation_post, ));

if ( $variation_post && $variation_post->post_type == 'product_variation' ) {

$variation_product = get_product( $variation_id );

if ( $variation_product && $variation_product->is_type( 'subscription_variation' ) ) {
wp_trash_post( $variation_id );
}
}
}
die();
}

除去&& $ variation_product-> is_type(“subscription_variation”)来解决未删除的变化的问题。 http://support.woothemes.com/requests/162693应该提供一个补丁,已报告的问题。



文章来源: Woocommerce - Cannot delete a product variation