本文整理汇总了PHP中WC_Admin_Meta_Boxes::add_error方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Admin_Meta_Boxes::add_error方法的具体用法?PHP WC_Admin_Meta_Boxes::add_error怎么用?PHP WC_Admin_Meta_Boxes::add_error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Admin_Meta_Boxes
的用法示例。
在下文中一共展示了WC_Admin_Meta_Boxes::add_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wc_redirects__wc_admin_process_product_meta
function wc_redirects__wc_admin_process_product_meta($post_id)
{
if (isset($_POST[WC_REDIRECTS__REDIRECTION_TYPE_META_NAME])) {
$value = $_POST[WC_REDIRECTS__REDIRECTION_TYPE_META_NAME];
$is_valid = false;
if ($value === '') {
$is_valid = true;
} else {
foreach (wc_redirects__get_valid_redirection_types() as $registration_type) {
if ($value === $registration_type['name']) {
$is_valid = true;
break;
}
}
}
if (!$is_valid) {
WC_Admin_Meta_Boxes::add_error(__('The selected Redirection Type is not valid.', 'wc_redirects'));
return;
}
if ($value === '') {
delete_post_meta($post_id, WC_REDIRECTS__REDIRECTION_TYPE_META_NAME);
} else {
update_post_meta($post_id, WC_REDIRECTS__REDIRECTION_TYPE_META_NAME, $value);
}
}
}
示例2: sync
/**
* Sync the variable product with it's children
*/
public static function sync($product_id)
{
global $wpdb;
$children = get_posts(array('post_parent' => $product_id, 'posts_per_page' => -1, 'post_type' => 'product_variation', 'fields' => 'ids', 'post_status' => 'publish'));
// No published variations - update parent post status. Use $wpdb to prevent endless loop on save_post hooks.
if (!$children && get_post_status($product_id) == 'publish') {
$wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $product_id));
if (is_admin()) {
WC_Admin_Meta_Boxes::add_error(__('This variable product has no active variations so cannot be published. Changing status to draft.', 'woocommerce'));
}
// Loop the variations
} else {
// Set the variable product to be virtual/downloadable if all children are virtual/downloadable
foreach (array('_downloadable', '_virtual') as $meta_key) {
$all_variations_yes = true;
foreach ($children as $child_id) {
if ('yes' != get_post_meta($child_id, $meta_key, true)) {
$all_variations_yes = false;
break;
}
}
update_post_meta($product_id, $meta_key, true === $all_variations_yes ? 'yes' : 'no');
}
// Main active prices
$min_price = null;
$max_price = null;
$min_price_id = null;
$max_price_id = null;
// Regular prices
$min_regular_price = null;
$max_regular_price = null;
$min_regular_price_id = null;
$max_regular_price_id = null;
// Sale prices
$min_sale_price = null;
$max_sale_price = null;
$min_sale_price_id = null;
$max_sale_price_id = null;
foreach (array('price', 'regular_price', 'sale_price') as $price_type) {
foreach ($children as $child_id) {
$child_price = get_post_meta($child_id, '_' . $price_type, true);
// Skip non-priced variations
if ($child_price === '') {
continue;
}
// Skip hidden variations
if ('yes' === get_option('woocommerce_hide_out_of_stock_items')) {
$stock = get_post_meta($child_id, '_stock', true);
if ($stock !== "" && $stock <= get_option('woocommerce_notify_no_stock_amount')) {
continue;
}
}
// Find min price
if (is_null(${"min_{$price_type}"}) || $child_price < ${"min_{$price_type}"}) {
${"min_{$price_type}"} = $child_price;
${"min_{$price_type}_id"} = $child_id;
}
// Find max price
if ($child_price > ${"max_{$price_type}"}) {
${"max_{$price_type}"} = $child_price;
${"max_{$price_type}_id"} = $child_id;
}
}
// Store prices
update_post_meta($product_id, '_min_variation_' . $price_type, ${"min_{$price_type}"});
update_post_meta($product_id, '_max_variation_' . $price_type, ${"max_{$price_type}"});
// Store ids
update_post_meta($product_id, '_min_' . $price_type . '_variation_id', ${"min_{$price_type}_id"});
update_post_meta($product_id, '_max_' . $price_type . '_variation_id', ${"max_{$price_type}_id"});
}
// The VARIABLE PRODUCT price should equal the min price of any type
update_post_meta($product_id, '_price', $min_price);
delete_transient('wc_products_onsale');
// Sync attributes
self::sync_attributes($product_id, $children);
do_action('woocommerce_variable_product_sync', $product_id, $children);
}
}
示例3: save
/**
* Save meta box data
*/
public static function save($post_id, $post)
{
global $wpdb;
// Ensure coupon code is correctly formatted
$post->post_title = apply_filters('woocommerce_coupon_code', $post->post_title);
$wpdb->update($wpdb->posts, array('post_title' => $post->post_title), array('ID' => $post_id));
// Check for dupe coupons
$coupon_found = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\tFROM {$wpdb->posts}\n\t\t\tWHERE {$wpdb->posts}.post_type = 'shop_coupon'\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\tAND {$wpdb->posts}.post_title = '%s'\n\t\t\tAND {$wpdb->posts}.ID != %s\n\t\t ", $post->post_title, $post_id));
if ($coupon_found) {
WC_Admin_Meta_Boxes::add_error(__('Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce'));
}
// Add/Replace data to array
$type = wc_clean($_POST['discount_type']);
$amount = wc_format_decimal($_POST['coupon_amount']);
$usage_limit = empty($_POST['usage_limit']) ? '' : absint($_POST['usage_limit']);
$usage_limit_per_user = empty($_POST['usage_limit_per_user']) ? '' : absint($_POST['usage_limit_per_user']);
$limit_usage_to_x_items = empty($_POST['limit_usage_to_x_items']) ? '' : absint($_POST['limit_usage_to_x_items']);
$individual_use = isset($_POST['individual_use']) ? 'yes' : 'no';
$expiry_date = wc_clean($_POST['expiry_date']);
$apply_before_tax = isset($_POST['apply_before_tax']) ? 'yes' : 'no';
$free_shipping = isset($_POST['free_shipping']) ? 'yes' : 'no';
$exclude_sale_items = isset($_POST['exclude_sale_items']) ? 'yes' : 'no';
$minimum_amount = wc_format_decimal($_POST['minimum_amount']);
$maximum_amount = wc_format_decimal($_POST['maximum_amount']);
$customer_email = array_filter(array_map('trim', explode(',', wc_clean($_POST['customer_email']))));
if (isset($_POST['product_ids'])) {
$product_ids = implode(',', array_filter(array_map('intval', (array) $_POST['product_ids'])));
} else {
$product_ids = '';
}
if (isset($_POST['exclude_product_ids'])) {
$exclude_product_ids = implode(',', array_filter(array_map('intval', (array) $_POST['exclude_product_ids'])));
} else {
$exclude_product_ids = '';
}
$product_categories = isset($_POST['product_categories']) ? array_map('intval', $_POST['product_categories']) : array();
$exclude_product_categories = isset($_POST['exclude_product_categories']) ? array_map('intval', $_POST['exclude_product_categories']) : array();
// Save
update_post_meta($post_id, 'discount_type', $type);
update_post_meta($post_id, 'coupon_amount', $amount);
update_post_meta($post_id, 'individual_use', $individual_use);
update_post_meta($post_id, 'product_ids', $product_ids);
update_post_meta($post_id, 'exclude_product_ids', $exclude_product_ids);
update_post_meta($post_id, 'usage_limit', $usage_limit);
update_post_meta($post_id, 'usage_limit_per_user', $usage_limit_per_user);
update_post_meta($post_id, 'limit_usage_to_x_items', $limit_usage_to_x_items);
update_post_meta($post_id, 'expiry_date', $expiry_date);
update_post_meta($post_id, 'apply_before_tax', $apply_before_tax);
update_post_meta($post_id, 'free_shipping', $free_shipping);
update_post_meta($post_id, 'exclude_sale_items', $exclude_sale_items);
update_post_meta($post_id, 'product_categories', $product_categories);
update_post_meta($post_id, 'exclude_product_categories', $exclude_product_categories);
update_post_meta($post_id, 'minimum_amount', $minimum_amount);
update_post_meta($post_id, 'maximum_amount', $maximum_amount);
update_post_meta($post_id, 'customer_email', $customer_email);
do_action('woocommerce_coupon_options_save', $post_id);
}
示例4: process_product_meta
/**
* Save subscription options.
*
* @param int $post_id
* @return void
*/
public static function process_product_meta($post_id)
{
// Get type.
$product_type = empty($_POST['product-type']) ? 'simple' : sanitize_title(stripslashes($_POST['product-type']));
$supported_types = WCS_ATT()->get_supported_product_types();
if (in_array($product_type, $supported_types)) {
// Save one time shipping option.
update_post_meta($post_id, '_subscription_one_time_shipping', stripslashes(isset($_POST['_subscription_one_time_shipping']) ? 'yes' : 'no'));
// Save subscription scheme options.
if (isset($_POST['wcsatt_schemes'])) {
$posted_schemes = stripslashes_deep($_POST['wcsatt_schemes']);
$unique_schemes = array();
foreach ($posted_schemes as $posted_scheme) {
// Copy variable type fields.
if ('variable' === $product_type) {
if (isset($posted_scheme['subscription_regular_price_variable'])) {
$posted_scheme['subscription_regular_price'] = $posted_scheme['subscription_regular_price_variable'];
}
if (isset($posted_scheme['subscription_sale_price_variable'])) {
$posted_scheme['subscription_sale_price'] = $posted_scheme['subscription_sale_price_variable'];
}
if (isset($posted_scheme['subscription_discount_variable'])) {
$posted_scheme['subscription_discount'] = $posted_scheme['subscription_discount_variable'];
}
if (isset($posted_scheme['subscription_pricing_method_variable'])) {
$posted_scheme['subscription_pricing_method'] = $posted_scheme['subscription_pricing_method_variable'];
}
}
// Format subscription prices.
if (isset($posted_scheme['subscription_regular_price'])) {
$posted_scheme['subscription_regular_price'] = $posted_scheme['subscription_regular_price'] === '' ? '' : wc_format_decimal($posted_scheme['subscription_regular_price']);
}
if (isset($posted_scheme['subscription_sale_price'])) {
$posted_scheme['subscription_sale_price'] = $posted_scheme['subscription_sale_price'] === '' ? '' : wc_format_decimal($posted_scheme['subscription_sale_price']);
}
if ('' !== $posted_scheme['subscription_sale_price']) {
$posted_scheme['subscription_price'] = $posted_scheme['subscription_sale_price'];
} else {
$posted_scheme['subscription_price'] = $posted_scheme['subscription_regular_price'] === '' ? '' : $posted_scheme['subscription_regular_price'];
}
// Format subscription discount.
if (isset($posted_scheme['subscription_discount'])) {
if (is_numeric($posted_scheme['subscription_discount'])) {
$discount = (double) wc_format_decimal($posted_scheme['subscription_discount']);
if ($discount < 0 || $discount > 100) {
WC_Admin_Meta_Boxes::add_error(__('Please enter positive subscription discount values, between 0-100.', WCS_ATT::TEXT_DOMAIN));
$posted_scheme['subscription_discount'] = '';
} else {
$posted_scheme['subscription_discount'] = $discount;
}
} else {
$posted_scheme['subscription_discount'] = '';
}
} else {
$posted_scheme['subscription_discount'] = '';
}
// Validate price override method.
if (isset($posted_scheme['subscription_pricing_method']) && $posted_scheme['subscription_pricing_method'] === 'override') {
if ($posted_scheme['subscription_price'] === '' && $posted_scheme['subscription_regular_price'] === '') {
$posted_scheme['subscription_pricing_method'] = 'inherit';
}
} else {
$posted_scheme['subscription_pricing_method'] = 'inherit';
}
// Construct scheme id.
$scheme_id = $posted_scheme['subscription_period_interval'] . '_' . $posted_scheme['subscription_period'] . '_' . $posted_scheme['subscription_length'];
$unique_schemes[$scheme_id] = $posted_scheme;
$unique_schemes[$scheme_id]['id'] = $scheme_id;
}
update_post_meta($post_id, '_wcsatt_schemes', $unique_schemes);
} else {
delete_post_meta($post_id, '_wcsatt_schemes');
}
// Save default status.
if (isset($_POST['_wcsatt_default_status'])) {
update_post_meta($post_id, '_wcsatt_default_status', stripslashes($_POST['_wcsatt_default_status']));
}
// Save one-time status.
$force_subscription = isset($_POST['_wcsatt_force_subscription']) ? 'yes' : 'no';
update_post_meta($post_id, '_wcsatt_force_subscription', $force_subscription);
// Set regular price as ZERO should the shop owner forget.
// This helps make WooCommerce think it's still available for purchase.
if ('yes' === $force_subscription && empty($_POST['_regular_price'])) {
update_post_meta($post_id, '_regular_price', wc_format_decimal(0));
update_post_meta($post_id, '_price', wc_format_decimal(0));
}
// Save prompt.
if (!empty($_POST['_wcsatt_subscription_prompt'])) {
$prompt = wp_kses_post(stripslashes($_POST['_wcsatt_subscription_prompt']));
update_post_meta($post_id, '_wcsatt_subscription_prompt', $prompt);
} else {
delete_post_meta($post_id, '_wcsatt_subscription_prompt');
}
} else {
//.........这里部分代码省略.........
示例5: save
/**
* Save meta box data.
*
* @param int $post_id
* @param WP_Post $post
*/
public static function save($post_id, $post)
{
global $wpdb;
// Check for dupe coupons
$coupon_code = apply_filters('woocommerce_coupon_code', $post->post_title);
$id_from_code = wc_get_coupon_id_by_code($coupon_code, $post_id);
if ($id_from_code) {
WC_Admin_Meta_Boxes::add_error(__('Coupon code already exists - customers will use the latest coupon with this code.', 'woocommerce'));
}
$coupon = new WC_Coupon($post_id);
$coupon->set_props(array('code' => $post->post_title, 'discount_type' => wc_clean($_POST['discount_type']), 'amount' => wc_format_decimal($_POST['coupon_amount']), 'date_expires' => wc_clean($_POST['expiry_date']), 'individual_use' => isset($_POST['individual_use']), 'product_ids' => array_filter(array_map('intval', explode(',', $_POST['product_ids']))), 'excluded_product_ids' => array_filter(array_map('intval', explode(',', $_POST['exclude_product_ids']))), 'usage_limit' => absint($_POST['usage_limit']), 'usage_limit_per_user' => absint($_POST['usage_limit_per_user']), 'limit_usage_to_x_items' => absint($_POST['limit_usage_to_x_items']), 'free_shipping' => isset($_POST['free_shipping']), 'product_categories' => array_filter(array_map('intval', (array) $_POST['product_categories'])), 'excluded_product_categories' => array_filter(array_map('intval', (array) $_POST['exclude_product_categories'])), 'exclude_sale_items' => isset($_POST['exclude_sale_items']), 'minimum_amount' => wc_format_decimal($_POST['minimum_amount']), 'maximum_amount' => wc_format_decimal($_POST['maximum_amount']), 'email_restrictions' => array_filter(array_map('trim', explode(',', wc_clean($_POST['customer_email']))))));
$coupon->save();
do_action('woocommerce_coupon_options_save', $post_id);
}
示例6: process_product_meta
/**
* Save subscription options.
*
* @param int $post_id
* @return void
*/
public static function process_product_meta($post_id)
{
// Get type.
$product_type = empty($_POST['product-type']) ? 'simple' : sanitize_title(stripslashes($_POST['product-type']));
$supported_types = WCS_ATT()->get_supported_product_types();
if (in_array($product_type, $supported_types)) {
// Save subscription scheme options.
if (isset($_POST['wcsatt_schemes'])) {
$posted_schemes = stripslashes_deep($_POST['wcsatt_schemes']);
$scheme_ids = array();
$clean_schemes = array();
foreach ($posted_schemes as $posted_scheme) {
// Format subscription prices.
if (isset($posted_scheme['subscription_regular_price'])) {
$posted_scheme['subscription_regular_price'] = $posted_scheme['subscription_regular_price'] === '' ? '' : wc_format_decimal($posted_scheme['subscription_regular_price']);
}
if (isset($posted_scheme['subscription_sale_price'])) {
$posted_scheme['subscription_sale_price'] = $posted_scheme['subscription_sale_price'] === '' ? '' : wc_format_decimal($posted_scheme['subscription_sale_price']);
}
if ('' !== $posted_scheme['subscription_sale_price']) {
$posted_scheme['subscription_price'] = $posted_scheme['subscription_sale_price'];
} else {
$posted_scheme['subscription_price'] = $posted_scheme['subscription_regular_price'] === '' ? '' : $posted_scheme['subscription_regular_price'];
}
// Format subscription discount.
if (isset($posted_scheme['subscription_discount'])) {
if (is_numeric($posted_scheme['subscription_discount'])) {
$discount = (double) wc_format_decimal($posted_scheme['subscription_discount']);
if ($discount < 0 || $discount > 100) {
WC_Admin_Meta_Boxes::add_error(__('Please enter positive subscription discount values, between 0-100.', WCS_ATT::TEXT_DOMAIN));
$posted_scheme['subscription_discount'] = '';
} else {
$posted_scheme['subscription_discount'] = $discount;
}
} else {
$posted_scheme['subscription_discount'] = '';
}
} else {
$posted_scheme['subscription_discount'] = '';
}
// Validate price override method.
if (isset($posted_scheme['subscription_pricing_method']) && $posted_scheme['subscription_pricing_method'] === 'override') {
if ($posted_scheme['subscription_price'] === '' && $posted_scheme['subscription_regular_price'] === '') {
$posted_scheme['subscription_pricing_method'] = 'inherit';
}
} else {
$posted_scheme['subscription_pricing_method'] = 'inherit';
}
// Construct scheme id.
$scheme_id = $posted_scheme['subscription_period_interval'] . '_' . $posted_scheme['subscription_period'] . '_' . $posted_scheme['subscription_length'];
if (in_array($scheme_id, $scheme_ids)) {
continue;
}
$posted_scheme['id'] = $scheme_id;
$scheme_ids[] = $scheme_id;
$clean_schemes[] = $posted_scheme;
}
update_post_meta($post_id, '_wcsatt_schemes', $clean_schemes);
} else {
delete_post_meta($post_id, '_wcsatt_schemes');
}
// Save default status
if (isset($_POST['_wcsatt_default_status'])) {
update_post_meta($post_id, '_wcsatt_default_status', stripslashes($_POST['_wcsatt_default_status']));
}
// Save one-time status
$force_subscription = isset($_POST['_wcsatt_force_subscription']) ? 'yes' : 'no';
update_post_meta($post_id, '_wcsatt_force_subscription', $force_subscription);
// Save prompt
if (!empty($_POST['_wcsatt_subscription_prompt'])) {
$prompt = wp_kses_post(stripslashes($_POST['_wcsatt_subscription_prompt']));
update_post_meta($post_id, '_wcsatt_subscription_prompt', $prompt);
} else {
delete_post_meta($post_id, '_wcsatt_subscription_prompt');
}
} else {
delete_post_meta($post_id, '_wcsatt_schemes');
delete_post_meta($post_id, '_wcsatt_force_subscription');
delete_post_meta($post_id, '_wcsatt_default_status');
delete_post_meta($post_id, '_wcsatt_subscription_prompt');
}
}
示例7: save
/**
* Save meta box data
*/
public static function save($post_id, $post)
{
global $wpdb;
// Add any default post meta
add_post_meta($post_id, 'total_sales', '0', true);
// Get types
$product_type = empty($_POST['product-type']) ? 'simple' : sanitize_title(stripslashes($_POST['product-type']));
$is_downloadable = isset($_POST['_downloadable']) ? 'yes' : 'no';
$is_virtual = isset($_POST['_virtual']) ? 'yes' : 'no';
// Product type + Downloadable/Virtual
wp_set_object_terms($post_id, $product_type, 'product_type');
update_post_meta($post_id, '_downloadable', $is_downloadable);
update_post_meta($post_id, '_virtual', $is_virtual);
// Update post meta
if (isset($_POST['_regular_price'])) {
update_post_meta($post_id, '_regular_price', $_POST['_regular_price'] === '' ? '' : wc_format_decimal($_POST['_regular_price']));
}
if (isset($_POST['_sale_price'])) {
update_post_meta($post_id, '_sale_price', $_POST['_sale_price'] === '' ? '' : wc_format_decimal($_POST['_sale_price']));
}
if (isset($_POST['_tax_status'])) {
update_post_meta($post_id, '_tax_status', stripslashes($_POST['_tax_status']));
}
if (isset($_POST['_tax_class'])) {
update_post_meta($post_id, '_tax_class', stripslashes($_POST['_tax_class']));
}
if (isset($_POST['_visibility'])) {
update_post_meta($post_id, '_visibility', stripslashes($_POST['_visibility']));
}
if (isset($_POST['_purchase_note'])) {
update_post_meta($post_id, '_purchase_note', stripslashes($_POST['_purchase_note']));
}
update_post_meta($post_id, '_featured', isset($_POST['_featured']) ? 'yes' : 'no');
// Dimensions
if ($is_virtual == 'no') {
if (isset($_POST['_weight'])) {
update_post_meta($post_id, '_weight', $_POST['_weight'] === '' ? '' : wc_format_decimal($_POST['_weight']));
}
if (isset($_POST['_length'])) {
update_post_meta($post_id, '_length', $_POST['_length'] === '' ? '' : wc_format_decimal($_POST['_length']));
}
if (isset($_POST['_width'])) {
update_post_meta($post_id, '_width', $_POST['_width'] === '' ? '' : wc_format_decimal($_POST['_width']));
}
if (isset($_POST['_height'])) {
update_post_meta($post_id, '_height', $_POST['_height'] === '' ? '' : wc_format_decimal($_POST['_height']));
}
} else {
update_post_meta($post_id, '_weight', '');
update_post_meta($post_id, '_length', '');
update_post_meta($post_id, '_width', '');
update_post_meta($post_id, '_height', '');
}
// Save shipping class
$product_shipping_class = $_POST['product_shipping_class'] > 0 && $product_type != 'external' ? absint($_POST['product_shipping_class']) : '';
wp_set_object_terms($post_id, $product_shipping_class, 'product_shipping_class');
// Unique SKU
$sku = get_post_meta($post_id, '_sku', true);
$new_sku = wc_clean(stripslashes($_POST['_sku']));
if ($new_sku == '') {
update_post_meta($post_id, '_sku', '');
} elseif ($new_sku !== $sku) {
if (!empty($new_sku)) {
if ($wpdb->get_var($wpdb->prepare("\n\t\t\t\t\t\tSELECT {$wpdb->posts}.ID\n\t\t\t\t\t FROM {$wpdb->posts}\n\t\t\t\t\t LEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\n\t\t\t\t\t WHERE {$wpdb->posts}.post_type = 'product'\n\t\t\t\t\t AND {$wpdb->posts}.post_status = 'publish'\n\t\t\t\t\t AND {$wpdb->postmeta}.meta_key = '_sku' AND {$wpdb->postmeta}.meta_value = '%s'\n\t\t\t\t\t ", $new_sku))) {
WC_Admin_Meta_Boxes::add_error(__('Product SKU must be unique.', 'woocommerce'));
} else {
update_post_meta($post_id, '_sku', $new_sku);
}
} else {
update_post_meta($post_id, '_sku', '');
}
}
// Save Attributes
$attributes = array();
if (isset($_POST['attribute_names']) && isset($_POST['attribute_values'])) {
$attribute_names = $_POST['attribute_names'];
$attribute_values = $_POST['attribute_values'];
if (isset($_POST['attribute_visibility'])) {
$attribute_visibility = $_POST['attribute_visibility'];
}
if (isset($_POST['attribute_variation'])) {
$attribute_variation = $_POST['attribute_variation'];
}
$attribute_is_taxonomy = $_POST['attribute_is_taxonomy'];
$attribute_position = $_POST['attribute_position'];
$attribute_names_count = sizeof($attribute_names);
for ($i = 0; $i < $attribute_names_count; $i++) {
if (!$attribute_names[$i]) {
continue;
}
$is_visible = isset($attribute_visibility[$i]) ? 1 : 0;
$is_variation = isset($attribute_variation[$i]) ? 1 : 0;
$is_taxonomy = $attribute_is_taxonomy[$i] ? 1 : 0;
if ($is_taxonomy) {
if (isset($attribute_values[$i])) {
// Select based attributes - Format values (posted values are slugs)
if (is_array($attribute_values[$i])) {
//.........这里部分代码省略.........
示例8: save_variations
/**
* Save meta box data.
*
* @param int $post_id
* @param WP_Post $post
*/
public static function save_variations($post_id, $post)
{
if (isset($_POST['variable_post_id'])) {
$parent = wc_get_product($post_id);
$max_loop = max(array_keys($_POST['variable_post_id']));
$data_store = $parent->get_data_store();
$data_store->sort_all_product_variations($parent->get_id());
for ($i = 0; $i <= $max_loop; $i++) {
if (!isset($_POST['variable_post_id'][$i])) {
continue;
}
$variation_id = absint($_POST['variable_post_id'][$i]);
$variation = new WC_Product_Variation($variation_id);
$errors = $variation->set_props(array('status' => isset($_POST['variable_enabled'][$i]) ? 'publish' : 'private', 'menu_order' => wc_clean($_POST['variation_menu_order'][$i]), 'regular_price' => wc_clean($_POST['variable_regular_price'][$i]), 'sale_price' => wc_clean($_POST['variable_sale_price'][$i]), 'virtual' => isset($_POST['variable_is_virtual'][$i]), 'downloadable' => isset($_POST['variable_is_downloadable'][$i]), 'date_on_sale_from' => wc_clean($_POST['variable_sale_price_dates_from'][$i]), 'date_on_sale_to' => wc_clean($_POST['variable_sale_price_dates_to'][$i]), 'description' => wp_kses_post(wc_sanitize_textarea($_POST['variable_description'][$i])), 'download_limit' => wc_clean($_POST['variable_download_limit'][$i]), 'download_expiry' => wc_clean($_POST['variable_download_expiry'][$i]), 'downloads' => self::prepare_downloads(isset($_POST['_wc_variation_file_names'][$variation_id]) ? $_POST['_wc_variation_file_names'][$variation_id] : array(), isset($_POST['_wc_variation_file_urls'][$variation_id]) ? $_POST['_wc_variation_file_urls'][$variation_id] : array(), isset($_POST['_wc_variation_file_hashes'][$variation_id]) ? $_POST['_wc_variation_file_hashes'][$variation_id] : array()), 'manage_stock' => isset($_POST['variable_manage_stock'][$i]), 'stock_quantity' => wc_clean($_POST['variable_stock'][$i]), 'backorders' => wc_clean($_POST['variable_backorders'][$i]), 'stock_status' => wc_clean($_POST['variable_stock_status'][$i]), 'image_id' => wc_clean($_POST['upload_image_id'][$i]), 'attributes' => self::prepare_set_attributes($parent->get_attributes(), 'attribute_', $i), 'sku' => isset($_POST['variable_sku'][$i]) ? wc_clean($_POST['variable_sku'][$i]) : '', 'weight' => isset($_POST['variable_weight'][$i]) ? wc_clean($_POST['variable_weight'][$i]) : '', 'length' => isset($_POST['variable_length'][$i]) ? wc_clean($_POST['variable_length'][$i]) : '', 'width' => isset($_POST['variable_width'][$i]) ? wc_clean($_POST['variable_width'][$i]) : '', 'height' => isset($_POST['variable_height'][$i]) ? wc_clean($_POST['variable_height'][$i]) : '', 'shipping_class_id' => wc_clean($_POST['variable_shipping_class'][$i]), 'tax_class' => wc_clean($_POST['variable_tax_class'][$i])));
if (is_wp_error($errors)) {
WC_Admin_Meta_Boxes::add_error($errors->get_error_message());
}
$variation->save();
do_action('woocommerce_save_product_variation', $variation_id, $i);
}
}
}
示例9: sync
/**
* Sync the variable product with it's children
*/
public static function sync($product_id)
{
global $wpdb;
$children = get_posts(array('post_parent' => $product_id, 'posts_per_page' => -1, 'post_type' => 'product_variation', 'fields' => 'ids', 'post_status' => 'publish'));
// No published variations - update parent post status. Use $wpdb to prevent endless loop on save_post hooks.
if (!$children && get_post_status($product_id) == 'publish') {
$wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $product_id));
if (is_admin()) {
WC_Admin_Meta_Boxes::add_error(__('This variable product has no active variations so cannot be published. Changing status to draft.', 'woocommerce'));
}
// Loop the variations
} else {
$min_price = null;
$max_price = null;
$min_price_id = null;
$max_price_id = null;
foreach ($children as $child) {
$child_price = get_post_meta($child, '_price', true);
if ($child_price === '') {
continue;
}
if ($child_price > $max_price) {
$max_price = $child_price;
$max_price_id = $child;
}
if (is_null($min_price) || $child_price < $min_price) {
$min_price = $child_price;
$min_price_id = $child;
}
}
// Store prices
update_post_meta($product_id, '_price', $min_price);
update_post_meta($product_id, '_min_variation_price', $min_price);
update_post_meta($product_id, '_max_variation_price', $max_price);
// Store IDS
update_post_meta($product_id, '_min_price_variation_id', $min_price_id);
update_post_meta($product_id, '_max_price_variation_id', $max_price_id);
do_action('woocommerce_variable_product_sync', $product_id, $children);
wc_delete_product_transients($product_id);
}
}
示例10: add_admin_error
/**
* Add and return admin errors.
*
* @param string $error
* @return string
*/
private function add_admin_error($error)
{
WC_Admin_Meta_Boxes::add_error($error);
return $error;
}
示例11: add_admin_error
/**
* Add admin errors.
*
* @param string $error
* @return string
*/
public function add_admin_error($error)
{
WC_Admin_Meta_Boxes::add_error($error);
}
示例12: easy_booking_save_variation_booking_options
public function easy_booking_save_variation_booking_options($variation_id, $i)
{
$is_bookable = isset($_POST['_var_booking_option'][$i]) ? 'yes' : '';
$data = array('booking_min' => $_POST['_var_booking_min'][$i], 'booking_max' => $_POST['_var_booking_max'][$i], 'first_available_date' => $_POST['_var_first_available_date'][$i]);
foreach ($data as $name => $value) {
switch ($value) {
case '':
${$name} = '';
break;
case 0:
${$name} = '0';
break;
default:
${$name} = absint($value);
break;
}
}
if ($booking_min != 0 && $booking_max != 0 && $booking_min > $booking_max) {
WC_Admin_Meta_Boxes::add_error(__('Minimum booking duration must be inferior to maximum booking duration', 'easy_booking'));
} else {
update_post_meta($variation_id, '_booking_min', $booking_min);
update_post_meta($variation_id, '_booking_max', $booking_max);
}
update_post_meta($variation_id, '_first_available_date', $first_available_date);
update_post_meta($variation_id, '_booking_option', $is_bookable);
}
示例13: get_storedfiles
/**
* return a list of available storedfiles
*/
public function get_storedfiles()
{
if (is_null($this->storedfiles)) {
// check of er een connectie is
if (!$this->connected) {
return false;
}
// Set authentication
$args = array('reject_unsafe_urls' => false, 'headers' => array('Authorization' => 'Basic ' . base64_encode($this->contractname . ':' . $this->contractpassword)));
$url = str_replace('ACCOUNTKEY', $this->accountkey, WC_BooXtream::listepubfilesurl) . '?limit=0';
$response = wp_safe_remote_get($url, $args);
if (is_array($response) && 200 === $response['response']['code']) {
$result = json_decode($response['body']);
if (is_object($result) && isset($result->message->response)) {
$this->storedfiles = array('' => __('Select an e-book', 'woocommerce_booxtream'));
foreach ($result->message->response as $file) {
if (isset($file->StoredFileKey)) {
$this->storedfiles[$file->StoredFileKey] = $file->FileName;
}
}
/*
* Save storedfiles
*/
update_option($this->plugin_id . $this->id . '_storedfiles', $this->storedfiles);
} else {
WC_Admin_Meta_Boxes::add_error(__('Could not retrieve list of stored files', 'woocommerce_booxtream'));
return false;
}
} else {
WC_Admin_Meta_Boxes::add_error(__('Could not retrieve list of stored files', 'woocommerce_booxtream'));
return false;
}
}
return $this->storedfiles;
}
示例14: sync
/**
* Sync the variable product with it's children.
*/
public static function sync($product_id)
{
global $wpdb;
$children = get_posts(array('post_parent' => $product_id, 'posts_per_page' => -1, 'post_type' => 'product_variation', 'fields' => 'ids', 'post_status' => 'publish'));
// No published variations - product won't be purchasable.
if (!$children) {
update_post_meta($product_id, '_price', '');
delete_transient('wc_products_onsale');
if (is_admin() && 'publish' === get_post_status($product_id)) {
WC_Admin_Meta_Boxes::add_error(__('This variable product has no active variations. Add or enable variations to allow this product to be purchased.', 'woocommerce'));
}
// Loop the variations
} else {
// Set the variable product to be virtual/downloadable if all children are virtual/downloadable
foreach (array('_downloadable', '_virtual') as $meta_key) {
$all_variations_yes = true;
foreach ($children as $child_id) {
if ('yes' != get_post_meta($child_id, $meta_key, true)) {
$all_variations_yes = false;
break;
}
}
update_post_meta($product_id, $meta_key, true === $all_variations_yes ? 'yes' : 'no');
}
// Main active prices
$min_price = null;
$max_price = null;
$min_price_id = null;
$max_price_id = null;
// Regular prices
$min_regular_price = null;
$max_regular_price = null;
$min_regular_price_id = null;
$max_regular_price_id = null;
// Sale prices
$min_sale_price = null;
$max_sale_price = null;
$min_sale_price_id = null;
$max_sale_price_id = null;
foreach (array('price', 'regular_price', 'sale_price') as $price_type) {
foreach ($children as $child_id) {
$child_price = get_post_meta($child_id, '_' . $price_type, true);
// Skip non-priced variations
if ($child_price === '') {
continue;
}
// Skip hidden variations
if ('yes' === get_option('woocommerce_hide_out_of_stock_items')) {
$stock = get_post_meta($child_id, '_stock', true);
if ($stock !== "" && $stock <= get_option('woocommerce_notify_no_stock_amount')) {
continue;
}
}
// Find min price
if (is_null(${"min_{$price_type}"}) || $child_price < ${"min_{$price_type}"}) {
${"min_{$price_type}"} = $child_price;
${"min_{$price_type}_id"} = $child_id;
}
// Find max price
if ($child_price > ${"max_{$price_type}"}) {
${"max_{$price_type}"} = $child_price;
${"max_{$price_type}_id"} = $child_id;
}
}
// Store prices
update_post_meta($product_id, '_min_variation_' . $price_type, ${"min_{$price_type}"});
update_post_meta($product_id, '_max_variation_' . $price_type, ${"max_{$price_type}"});
// Store ids
update_post_meta($product_id, '_min_' . $price_type . '_variation_id', ${"min_{$price_type}_id"});
update_post_meta($product_id, '_max_' . $price_type . '_variation_id', ${"max_{$price_type}_id"});
}
// Sync _price meta
delete_post_meta($product_id, '_price');
add_post_meta($product_id, '_price', $min_price, false);
add_post_meta($product_id, '_price', $max_price, false);
delete_transient('wc_products_onsale');
// Sync attributes
self::sync_attributes($product_id, $children);
do_action('woocommerce_variable_product_sync', $product_id, $children);
}
}
示例15: process_meta
/**
* Process, verify and save product data
* @param int $post_id
* @return void
*/
public static function process_meta($post_id)
{
// Min container size
$min_qty = intval(get_post_meta($post_id, '_mnm_container_size', true));
// Max container size
$max_qty = isset($_POST['mnm_max_container_size']) ? intval(wc_clean($_POST['mnm_max_container_size'])) : $min_qty;
if ($max_qty > 0 && $min_qty > $max_qty) {
$max_qty = $min_qty;
WC_Admin_Meta_Boxes::add_error(__('The maximum Mix & Match container size cannot be smaller than the minimum container size.', 'woocommerce-mix-and-match-min-max-quantities'));
}
update_post_meta($post_id, '_mnm_max_container_size', $max_qty);
return $post_id;
}
开发者ID:unsub,项目名称:woocommerce-mix-and-match-min-max,代码行数:18,代码来源:woocommerce-mix-and-match-min-max-quantities.php