本文整理汇总了PHP中WC_Admin_Meta_Boxes::meta_box_errors方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Admin_Meta_Boxes::meta_box_errors方法的具体用法?PHP WC_Admin_Meta_Boxes::meta_box_errors怎么用?PHP WC_Admin_Meta_Boxes::meta_box_errors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Admin_Meta_Boxes
的用法示例。
在下文中一共展示了WC_Admin_Meta_Boxes::meta_box_errors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_variations
/**
* Save variations via AJAX.
*/
public static function save_variations()
{
ob_start();
check_ajax_referer('save-variations', 'security');
// Check permissions again and make sure we have what we need
if (!current_user_can('edit_products') || empty($_POST) || empty($_POST['product_id'])) {
die(-1);
}
// Remove previous meta box errors
WC_Admin_Meta_Boxes::$meta_box_errors = array();
$product_id = absint($_POST['product_id']);
$product_type = empty($_POST['product-type']) ? 'simple' : sanitize_title(stripslashes($_POST['product-type']));
$product_type_terms = wp_get_object_terms($product_id, 'product_type');
// If the product type hasn't been set or it has changed, update it before saving variations
if (empty($product_type_terms) || $product_type !== sanitize_title(current($product_type_terms)->name)) {
wp_set_object_terms($product_id, $product_type, 'product_type');
}
WC_Meta_Box_Product_Data::save_variations($product_id, get_post($product_id));
do_action('woocommerce_ajax_save_product_variations', $product_id);
// Clear cache/transients
wc_delete_product_transients($product_id);
if ($errors = WC_Admin_Meta_Boxes::$meta_box_errors) {
echo '<div class="error notice is-dismissible">';
foreach ($errors as $error) {
echo '<p>' . wp_kses_post($error) . '</p>';
}
echo '<button type="button" class="notice-dismiss"><span class="screen-reader-text">' . __('Dismiss this notice.', 'woocommerce') . '</span></button>';
echo '</div>';
delete_option('woocommerce_meta_box_errors');
}
die;
}
示例2: save_variations
/**
* Save variations via AJAX
*/
public static function save_variations()
{
ob_start();
check_ajax_referer('save-variations', 'security');
// Check permissions again and make sure we have what we need
if (!current_user_can('edit_products') || empty($_POST) || empty($_POST['product_id'])) {
die(-1);
}
// Remove previous meta box errors
WC_Admin_Meta_Boxes::$meta_box_errors = array();
$product_id = absint($_POST['product_id']);
WC_Meta_Box_Product_Data::save_variations($product_id, get_post($product_id));
do_action('woocommerce_ajax_save_product_variations', $product_id);
// Clear cache/transients
wc_delete_product_transients($product_id);
if ($errors = WC_Admin_Meta_Boxes::$meta_box_errors) {
echo '<div class="error notice is-dismissible">';
foreach ($errors as $error) {
echo '<p>' . wp_kses_post($error) . '</p>';
}
echo '<button type="button" class="notice-dismiss"><span class="screen-reader-text">' . __('Dismiss this notice.', 'woocommerce') . '</span></button>';
echo '</div>';
delete_option('woocommerce_meta_box_errors');
}
die;
}