當前位置: 首頁>>代碼示例>>PHP>>正文


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怎麽用?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;
 }
開發者ID:tronsha,項目名稱:woocommerce,代碼行數:35,代碼來源:class-wc-ajax.php

示例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;
 }
開發者ID:kythanbao,項目名稱:woocommerce,代碼行數:29,代碼來源:class-wc-ajax.php


注:本文中的WC_Admin_Meta_Boxes::meta_box_errors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。