From 071f08f057753e54331d23b79a9a90afe48fa796 Mon Sep 17 00:00:00 2001 From: gine Date: Fri, 24 Aug 2018 12:33:41 +0200 Subject: [PATCH] Incluse pull request fino alla #11 --- includes/class-wcqu-actions.php | 76 +++--- includes/class-wcqu-filters.php | 10 +- includes/class-wcqu-post-type.php | 327 ++++++++++++----------- includes/class-wcqu-product-meta-box.php | 140 +++++----- includes/class-wcqu-product-unit.php | 6 +- includes/class-wcqu-units-box.php | 4 +- includes/wcqu-functions.php | 40 +-- quantites-and-units.php | 6 +- readme.txt | 26 +- 9 files changed, 326 insertions(+), 309 deletions(-) diff --git a/includes/class-wcqu-actions.php b/includes/class-wcqu-actions.php index f96a610..1e8922e 100755 --- a/includes/class-wcqu-actions.php +++ b/includes/class-wcqu-actions.php @@ -1,89 +1,91 @@ -product_type == 'grouped' ) + */ + + if( $product->is_type('grouped') ) return; - + $settings = get_option( 'ipq_options' ); extract( $settings ); - - // Get minimum value for product + + // Get minimum value for product $rule = wcqu_get_applied_rule( $product ); - + // Return nothing if APQ is deactivated if ( $rule == 'inactive' or $rule == null ) { - return; + return; } - - // Check if the product is out of stock + + // Check if the product is out of stock $stock = $product->get_stock_quantity(); // Check if the product is under stock management and out of stock @@ -93,7 +95,7 @@ public function display_minimum_quantity_note() { } else { $min = wcqu_get_value_from_rule( 'min', $product, $rule ); $max = wcqu_get_value_from_rule( 'max', $product, $rule ); - } + } $step = wcqu_get_value_from_rule( 'step', $product, $rule ); @@ -101,25 +103,25 @@ public function display_minimum_quantity_note() { if ( $rule == 'sitewide' and strlen( $stock ) != 0 and $stock <= 0 ) { if ( is_array( $min ) ) $min = $min['min_oos']; - + if ( is_array( $max ) ) $max = $max['max_oos']; - + if ( is_array( $step ) ) { $step = $step['step']; } } else if ( $rule == 'sitewide' ) { if ( is_array( $min ) ) $min = $min['min']; - + if ( is_array( $max ) ) $max = $max['max']; - + if ( is_array( $step ) ) { $step = $step['step']; } } - + // If the text is set, update and print the output if ( isset( $ipq_qty_text ) ) { $min_pattern = '/\%MIN\%/'; @@ -134,7 +136,7 @@ public function display_minimum_quantity_note() { echo ""; + echo ">"; echo $ipq_qty_text; echo ""; } diff --git a/includes/class-wcqu-filters.php b/includes/class-wcqu-filters.php index 00d237a..8278c96 100755 --- a/includes/class-wcqu-filters.php +++ b/includes/class-wcqu-filters.php @@ -31,7 +31,7 @@ public function __construct() { */ public function woocommerce_loop_add_to_cart_args( $args, $product ) { // Return Defaults if it isn't a simple product - if( $product->product_type != 'simple' ) { + if( ! $product->is_type( 'simple' ) ) { return $args; } @@ -68,7 +68,7 @@ public function woocommerce_loop_add_to_cart_args( $args, $product ) { public function input_min_value( $default, $product ) { // Return Defaults if it isn't a simple product - if( $product->product_type != 'simple' ) { + if( ! $product->is_type( 'simple' ) ) { return $default; } @@ -97,7 +97,7 @@ public function input_min_value( $default, $product ) { public function input_max_value( $default, $product ) { // Return Defaults if it isn't a simple product - if( $product->product_type != 'simple' ) { + if( ! $product->is_type( 'simple' ) ) { return $default; } @@ -127,7 +127,7 @@ public function input_max_value( $default, $product ) { public function input_step_value( $default, $product ) { // Return Defaults if it isn't a simple product - if( $product->product_type != 'simple' ) { + if( ! $product->is_type( 'simple' ) ) { return $default; } @@ -159,7 +159,7 @@ public function input_set_all_values( $args, $product ) { // Return Defaults if it isn't a simple product /* Commented out to allow for grouped and variable products * on their product pages - if( $product->product_type != 'simple' ) { + if( ! $product->is_type( 'simple' ) ) { return $args; } */ diff --git a/includes/class-wcqu-post-type.php b/includes/class-wcqu-post-type.php index 5156680..387963f 100755 --- a/includes/class-wcqu-post-type.php +++ b/includes/class-wcqu-post-type.php @@ -1,20 +1,20 @@ - __('Quantity Rules','qau'), 'singular_name' => __('Quantity Rule','qau'), @@ -49,7 +49,7 @@ public function quantity_rule_init() { 'parent_item_colon' => '', 'menu_name' => __('Quantity Rules','qau'), ); - + $args = array( 'labels' => $labels, 'public' => false, @@ -65,21 +65,21 @@ public function quantity_rule_init() { 'supports' => array( 'title' ), 'taxonomies' => array(), ); - + register_post_type( 'quantity-rule', $args ); } - + /* * Register Custom Columns for List View - */ + */ public function quantity_rule_columns( $column ) { - + unset( $column['date'] ); - + $new_columns['priority'] = __('Priority'); $new_columns['min'] = __('Minimum'); $new_columns['max'] = __('Maximum'); - $new_columns['step'] = __('Step Value'); + $new_columns['step'] = __('Step Value'); $new_columns['cats'] = __('Categories'); $new_columns['product_tags'] = __('Tags'); $new_columns['roles'] = __('Roles'); @@ -87,101 +87,106 @@ public function quantity_rule_columns( $column ) { return array_merge( $column, $new_columns ); } - + /* * Get Custom Columns Values for List View - */ + */ public function manage_quantity_rule_columns($column_name, $id) { - + switch ($column_name) { - + case 'priority': echo get_post_meta( $id, '_priority', true ); break; - + case 'min': echo get_post_meta( $id, '_min', true ); break; - + case 'max': echo get_post_meta( $id, '_max', true ); break; - + case 'step': - echo get_post_meta( $id, '_step', true ); + echo get_post_meta( $id, '_step', true ); break; - + case 'cats': $cats = get_post_meta( $id, '_cats', false); - if ( $cats != false and count( $cats[0] ) > 0 ) { + if ( $cats != false and count( $cats[0] ) > 0 ) { foreach ( $cats[0] as $cat ){ - - $taxonomy = 'product_cat'; + + $taxonomy = 'product_cat'; $term = get_term_by( 'id', $cat, $taxonomy ); - $link = get_term_link( $term ); - - echo "" . $term->name . "
"; + $link = get_term_link( $term ); + + if ( !$term || is_wp_error( $link ) ) { + echo "Unknown / Deleted Category
"; + continue; + } + + echo "" . $term->name . "
"; } - } - break; - + } + break; + case 'product_tags': $tags = get_post_meta( $id, '_tags', false); - if ( $tags != null and count( $tags[0] ) > 0) { + if ( $tags != null and count( $tags[0] ) > 0) { foreach ( $tags[0] as $tag ){ - - $taxonomy = 'product_tag'; + + $taxonomy = 'product_tag'; $term = get_term_by( 'id', $tag, $taxonomy ); - $link = get_term_link( $term ); - - echo "" . $term->name . "
"; + $link = get_term_link( $term ); + + echo "" . $term->name . "
"; } - } + } break; - + case 'roles': $roles = get_post_meta( $id, '_roles', false); - if ( $roles != null and count( $roles[0] ) > 0) { + if ( $roles != null and count( $roles[0] ) > 0) { foreach ( $roles[0] as $role ){ - echo ucfirst( $role ) . "
"; + echo ucfirst( $role ) . "
"; } - } + } break; - + default: break; - } - } - + } + } + /* * Make Custom Columns Sortable - */ - public function sortable_quantity_rule_columns( $columns ) { - + */ + public function sortable_quantity_rule_columns( $columns ) { + $columns['priority'] = __('Priority'); $columns['min'] = __('Minimum'); $columns['max'] = __('Maximum'); $columns['step'] = __('Step Value'); - - return $columns; - } - + + return $columns; + } + /* * Register and Create Rule Options Meta Box for Quantity Rules - */ + */ public function quantity_rule_meta_init() { add_meta_box( - 'wpbo-quantity-rule-meta', - 'Set Quantity Rule Options', - array( $this, 'quantity_rule_meta' ), - 'quantity-rule', - 'normal', + 'wpbo-quantity-rule-meta', + 'Set Quantity Rule Options', + array( $this, 'quantity_rule_meta' ), + 'quantity-rule', + 'normal', 'high' ); } - + public function quantity_rule_meta( $post ) { - + $min = get_post_meta( $post->ID, '_min', true); $max = get_post_meta( $post->ID, '_max', true); $min_oos = get_post_meta( $post->ID, '_min_oos', true ); @@ -190,10 +195,10 @@ public function quantity_rule_meta( $post ) { $max_sale = get_post_meta( $post->ID, '_max_sale', true ); $step = get_post_meta( $post->ID, '_step', true); $priority = get_post_meta( $post->ID, '_priority', true); - + // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_rule_value_nonce' ); - + ?>
@@ -224,10 +229,10 @@ public function quantity_rule_meta( $post ) {

ID, '_cats', false); - + if ( $cats != null ) { $cats = $cats[0]; } - + // Get all possible categories $tax_name = 'product_cat'; - - $args = array( + + $args = array( 'parent' => 0, 'hide_empty' => false ); - + $terms = get_terms( $tax_name, $args ); - + if ( $terms ){ - + // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_tax_nonce' ); - + echo '
    '; foreach ( $terms as $term ) { $this->print_tax_inputs( $term, $tax_name, $cats, 2 ); @@ -270,22 +275,22 @@ function quantity_rule_tax_meta( $post ) { echo '
'; } } - + /* * Will Recursivly Print all Product Categories with heirarcy included */ - public function print_tax_inputs( $term, $taxonomy_name, $cats, $level ) { - + public function print_tax_inputs( $term, $taxonomy_name, $cats, $level ) { + // Echo Single Item ?>
  • term_id, $cats )) echo 'checked="checked"' ?> />name; ?>
  • - term_id, $taxonomy_name ); - + // Continue to print children if they exist if ( $children ){ echo '
      '; @@ -300,10 +305,10 @@ public function print_tax_inputs( $term, $taxonomy_name, $cats, $level ) { echo '
    '; } } - + /* * Allow users to apply rules by tags - */ + */ public function quantity_rule_tag_init() { add_meta_box( 'wpbo-quantity-rule-tag-meta', @@ -314,19 +319,19 @@ public function quantity_rule_tag_init() { 'high' ); } - + public function quantity_rule_tag_meta( $post ) { - + // Get all Tags $args = array( - 'orderby' => 'name', + 'orderby' => 'name', 'order' => 'ASC', - 'hide_empty' => false, - - ); + 'hide_empty' => false, + + ); $tags = get_terms( 'product_tag', $args ); - + $included_tags = get_post_meta( $post->ID, '_tags'); if ( $included_tags != false ){ $included_tags = $included_tags[0]; @@ -334,7 +339,7 @@ public function quantity_rule_tag_meta( $post ) { // If Tags exists, show them all if ( $tags ) { - + // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_tag_nonce' ); @@ -347,13 +352,13 @@ public function quantity_rule_tag_meta( $post ) { - get_names(); - + // Get applied roles $applied_roles = get_post_meta( $post->ID, '_roles' ); if ( $applied_roles != false ){ @@ -378,7 +383,7 @@ public function quantity_rule_role( $post ) { } // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_role_nonce' ); - + if ( $roles ): ?>
      $name ): ?> @@ -397,9 +402,9 @@ public function quantity_rule_role( $post ) { /* * Register and Create Meta Box to encourage user to install our thumbnail plugin - */ + */ public function input_thumbnail_notice() { - + // Only show meta box if user has not installed thumbnail plugin if ( !in_array( 'woocommerce-thumbnail-input-quantities/woocommerce-thumbnail-input-quantity.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { @@ -413,14 +418,14 @@ public function input_thumbnail_notice() { ); } } - + public function input_thumbnail_notice_meta( $post ) { echo __('We have noticed you do not have WooCommerce Thumbnail Input Quantity installed.

      Installation is highly recommended as it shows an input box (with your quantity rules) from all product thumbnails such as on the shop page and in the related prodcuts section.','qau'); } /* * Register and Create Meta Box to encourage user to install our thumbnail plugin - */ + */ public function rate_us_notice() { add_meta_box( @@ -432,7 +437,7 @@ public function rate_us_notice() { 'low' ); } - + public function additional_info_notice_meta( $post ) { ?>
      @@ -442,36 +447,36 @@ public function additional_info_notice_meta( $post ) {

      - get_names(); foreach ( $roles as $slug => $name ) { delete_transient( 'ipq_rules_' . $slug ); } - + //Also delete the guest transient, which is not a role delete_transient( 'ipq_rules_guest' ); @@ -480,14 +485,14 @@ public function save_quantity_rule_meta( $post_id ) { if( isset( $_POST['min'] ) ) { $min = $_POST['min']; } - - // Update Step + + // Update Step if ( isset( $_POST['step'] ) and isset( $min ) ) { if ( $min < $_POST['step'] && $min > 0) { $min = $_POST['step']; } } - + // Get Min Out of Stock if( isset( $_POST['min_oos'] ) ) { $min_oos = $_POST['min_oos']; @@ -503,34 +508,34 @@ public function save_quantity_rule_meta( $post_id ) { if ( isset( $min ) ) { update_post_meta( $post_id, '_min', stripslashes( $min ) ); } - + // Update Max if ( isset( $_POST['max'] ) ) { $max = $_POST['max']; - + // Validate Max is not less then Min if ( isset( $min ) and $max < $min and $max != 0 ) { $max = $min; } - + update_post_meta( $post_id, '_max', wcqu_validate_number( $max ) ); } - + // Update Max OOS if ( isset( $_POST['max_oos'] ) ) { $max_oos = $_POST['max_oos']; - + // Max must be bigger then min if ( $max_oos != '' and isset( $min_oos ) and $min_oos != 0 ) { if ( $min_oos > $max_oos ) $max_oos = $min_oos; - + } elseif ( $max_oos != '' and isset( $min ) and $min != 0 ){ if ( $min > $max_oos ) { $max_oos = $min; } } - + update_post_meta( $post_id, '_max_oos', wcqu_validate_number( $max_oos ) ); } @@ -556,135 +561,135 @@ public function save_quantity_rule_meta( $post_id ) { if ( isset( $_POST['step'] ) ) { update_post_meta( $post_id, '_step', wcqu_validate_number( $_POST['step'] ) ); } - + // Update Priority if ( isset( $_POST['priority'] ) ) { update_post_meta( $post_id, '_priority', wcqu_validate_number( $_POST['priority'] ) ); } - + } - + /* * Save Rule Taxonomy Values - */ + */ public function save_quantity_rule_taxes( $post_id ) { - + // Validate Post Type if ( ! isset( $_POST['post_type'] ) or $_POST['post_type'] !== 'quantity-rule' ) { return; } - + // Validate User if ( !current_user_can( 'edit_post', $post_id ) ) { return; } - + // Verify Nonce if ( ! isset( $_POST["_wpbo_tax_nonce"] ) or ! wp_verify_nonce( $_POST["_wpbo_tax_nonce"], plugin_basename( __FILE__ ) ) ) { return; } - + // Check which Categories have been selected $tax_name = 'product_cat'; $args = array( 'hide_empty' => false ); $terms = get_terms( $tax_name, $args ); $cats = array(); - + // See which terms were included foreach ( $terms as $term ) { $term_name = '_wpbo_cat_' . $term->term_id; if ( isset( $_POST[ $term_name ] ) and $_POST[ $term_name ] == 'on' ) { - array_push( $cats, $term->term_id ); - } + array_push( $cats, $term->term_id ); + } } - + // Add them to the post meta delete_post_meta( $post_id, '_cats' ); update_post_meta( $post_id, '_cats', $cats, false ); - } - + } + /* * Save Rule Tag Values - */ + */ public function save_quantity_rule_tags( $post_id ) { - + // Validate Post Type if ( ! isset( $_POST['post_type'] ) or $_POST['post_type'] !== 'quantity-rule' ) { return; } - + // Validate User if ( !current_user_can( 'edit_post', $post_id ) ) { return; } - + // Verify Nonce if ( ! isset( $_POST["_wpbo_tag_nonce"] ) or ! wp_verify_nonce( $_POST["_wpbo_tag_nonce"], plugin_basename( __FILE__ ) ) ) { return; } - + // Get all Tags $args = array ( - 'orderby' => 'name', + 'orderby' => 'name', 'order' => 'ASC', - 'hide_empty' => false, - ); + 'hide_empty' => false, + ); $tags = get_terms( 'product_tag', $args ); - + $tags_included = array(); - + // If the tags are set, loop through them if ( $tags ) { foreach ( $tags as $tag ) { - + $tag_name = '_wpbo_tag_' . $tag->term_id; if ( isset( $_POST[ $tag_name ] ) and $_POST[ $tag_name ] == 'on' ) { - array_push( $tags_included, $tag->term_id ); - } + array_push( $tags_included, $tag->term_id ); + } } - + // Add them to the post meta delete_post_meta( $post_id, '_tags' ); update_post_meta( $post_id, '_tags', $tags_included, false ); } } - + /* * Save Rule Role Values - */ + */ public function save_quantity_rule_roles( $post_id ) { - + // Validate Post Type if ( ! isset( $_POST['post_type'] ) or $_POST['post_type'] !== 'quantity-rule' ) { return; } - + // Validate User if ( !current_user_can( 'edit_post', $post_id ) ) { return; } - + // Verify Nonce if ( ! isset( $_POST["_wpbo_role_nonce"] ) or ! wp_verify_nonce( $_POST["_wpbo_role_nonce"], plugin_basename( __FILE__ ) ) ) { return; } - + // Get available user roles global $wp_roles; $roles = $wp_roles->get_names(); $applied_roles = array(); - + // Loop through roles foreach ( $roles as $slug => $name ) { $role_name = '_wpbo_role_' . $slug; - + // If role is set add it to the applied list if ( isset( $_POST[ $role_name ] ) and $_POST[ $role_name ] == 'on' ) { array_push( $applied_roles, $slug ); } } - + // If guest role is set add it to the applied list if ( isset( $_POST[ '_wpbo_role_guest' ] ) and $_POST[ '_wpbo_role_guest' ] == 'on' ) { array_push( $applied_roles, 'guest' ); @@ -694,8 +699,8 @@ public function save_quantity_rule_roles( $post_id ) { // Add them to the post meta delete_post_meta( $post_id, '_roles' ); update_post_meta( $post_id, '_roles', $applied_roles, false ); - - } + + } } endif; diff --git a/includes/class-wcqu-product-meta-box.php b/includes/class-wcqu-product-meta-box.php index 67f7391..f18ecac 100755 --- a/includes/class-wcqu-product-meta-box.php +++ b/includes/class-wcqu-product-meta-box.php @@ -1,12 +1,12 @@ -post_type == 'product' ) { - - $product = get_product( $post->ID ); + + $product = wc_get_product( $post->ID ); $unsupported_product_types = array( 'external', 'grouped' ); - if ( ! in_array( $product->product_type, $unsupported_product_types ) ) { - + if ( ! $product->is_type( $unsupported_product_types ) ) { + add_meta_box( 'wpbo_product_info', __('Product Quantity Rules', 'qau'), @@ -35,22 +35,22 @@ public function meta_box_create() { } } } - + /* * Display Rule Meta Box */ function product_meta_box_content( $post ) { global $product; - global $woocommerce; + global $wp_roles; - + // Get the product and see what rules are being applied $pro = wc_get_product( $post ); // Get applied rules by user role $roles = $wp_roles->get_names(); $roles['guest'] = "Guest"; - + $rules_by_role = array(); $rule = null; @@ -89,8 +89,8 @@ function product_meta_box_content( $post ) {
    - -
    + +
    @@ -135,8 +135,8 @@ function product_meta_box_content( $post ) { - -
    + +
    @@ -152,7 +152,7 @@ function product_meta_box_content( $post ) { $rule ): ?> @@ -181,7 +181,7 @@ function product_meta_box_content( $post ) { ID, '_wpbo_deactive', true ); $step = get_post_meta( $post->ID, '_wpbo_step', true ); @@ -195,8 +195,8 @@ function product_meta_box_content( $post ) { // Create Nonce Field wp_nonce_field( plugin_basename( __FILE__ ), '_wpbo_product_rule_nonce' ); - - // Print the form ?> + + // Print the form ?>
    /> @@ -232,65 +232,65 @@ function product_meta_box_content( $post ) {
    = step */ /* if ( isset( $step ) and isset( $min ) ) { @@ -314,69 +314,69 @@ public function save_quantity_meta_data( $post_id ) { if ( $min != 0 ) { $min = wcqu_validate_number( $min ); } - update_post_meta( - $post_id, - '_wpbo_minimum', + update_post_meta( + $post_id, + '_wpbo_minimum', strip_tags( $min ) ); } - + /* Make sure Max > Min */ if( isset( $_POST['_wpbo_maximum'] ) && ! empty($_POST['_wpbo_maximum']) ) { $max = $_POST['_wpbo_maximum']; if ( isset( $min ) and $max < $min and $max != 0 ) { $max = $min; } - - update_post_meta( - $post_id, - '_wpbo_maximum', + + update_post_meta( + $post_id, + '_wpbo_maximum', strip_tags( wcqu_validate_number( $max ) ) ); } - + // Update Out of Stock Minimum if( isset( $_POST['_wpbo_minimum_oos'] ) && ! empty($_POST['_wpbo_minimum_oos']) ) { $min_oos = stripslashes( $_POST['_wpbo_minimum_oos'] ); - + if ( $min_oos != 0 ) { $min_oos = wcqu_validate_number( $min_oos ); } - update_post_meta( - $post_id, - '_wpbo_minimum_oos', + update_post_meta( + $post_id, + '_wpbo_minimum_oos', strip_tags( $min_oos ) ); } - + // Update Out of Stock Maximum if( isset( $_POST['_wpbo_maximum_oos'] ) && ! empty($_POST['_wpbo_maximum_oos'])) { $max_oos = stripslashes( $_POST['_wpbo_maximum_oos'] ); - + // Allow the value to be unset if ( $max_oos != '' ) { - - // Validate the number + + // Validate the number if ( $max_oos != 0 ) { $max_oos = wcqu_validate_number( $max_oos ); - } - + } + // Max must be bigger then min if ( isset( $min_oos ) and $min_oos != 0 ) { if ( $min_oos > $max_oos ) $max_oos = $min_oos; - + } elseif ( isset( $min ) and $min != 0 ){ if ( $min > $max_oos ) { $max_oos = $min; } } - } - - update_post_meta( - $post_id, - '_wpbo_maximum_oos', + } + + update_post_meta( + $post_id, + '_wpbo_maximum_oos', strip_tags( $max_oos ) ); diff --git a/includes/class-wcqu-product-unit.php b/includes/class-wcqu-product-unit.php index b12c154..5b5df1e 100644 --- a/includes/class-wcqu-product-unit.php +++ b/includes/class-wcqu-product-unit.php @@ -61,7 +61,7 @@ public function get_unit_for_product( $product_id, $default = null ) { */ public function get_price_suffix( $price_display_suffix, $product ) { // todo make default unit configuarble - if ( $unit = $this->get_unit_for_product( $product->id, apply_filters( 'wciu_default_price_suffix', __( '', 'qau' ) ) ) ) { + if ( $unit = $this->get_unit_for_product( $product->get_id(), apply_filters( 'wciu_default_price_suffix', __( '', 'qau' ) ) ) ) { $price_display_suffix = "/" . $unit . " " . $price_display_suffix; } @@ -77,7 +77,7 @@ public function get_price_suffix( $price_display_suffix, $product ) { * @return string */ public function sale_price_from_to( $price, $from, $to, $product ) { - if ( $unit = get_post_meta( $product->id, 'unit', true ) ) { + if ( $unit = get_post_meta( $product->get_id(), 'unit', true ) ) { $price = '' . ( ( is_numeric( $from ) ) ? wc_price( $from ) : $from ) . '/' . $unit . '' . ( ( is_numeric( $to ) ) ? wc_price( $to ) : $to ) . '/' . $unit . ''; } @@ -91,7 +91,7 @@ public function sale_price_from_to( $price, $from, $to, $product ) { * @return string */ public function price_html( $html, $product ) { - $unit = get_post_meta( $product->id, 'unit', true ); + $unit = get_post_meta( $product->get_id(), 'unit', true ); if ( $unit ) { return $html . '/' . $unit; } diff --git a/includes/class-wcqu-units-box.php b/includes/class-wcqu-units-box.php index 9f460ee..354bc5e 100644 --- a/includes/class-wcqu-units-box.php +++ b/includes/class-wcqu-units-box.php @@ -5,13 +5,13 @@ class WC_Quantities_and_Units_Units_Box { public function __construct() { - add_action( 'woocommerce_product_write_panels', array( $this, 'units_box_create' ) ); + add_action( 'woocommerce_product_data_panels', array( $this, 'units_box_create' ) ); add_action( 'save_post', array( $this, 'save_unit_meta_data' ) ); add_action( 'woocommerce_product_write_panel_tabs', array($this, 'units_box_tab'), 99 ); } function units_box_tab() { - echo '
  • '.__('Unit','qau').'
  • '; + echo '
  • ' . __( 'Unit', 'qau' ). '
  • '; } public function units_box_create() { diff --git a/includes/wcqu-functions.php b/includes/wcqu-functions.php index 1d844ca..dcc0c0c 100755 --- a/includes/wcqu-functions.php +++ b/includes/wcqu-functions.php @@ -13,10 +13,10 @@ function wcqu_get_applied_rule( $product, $role = null ) { // Check for site wide rule $options = get_option( 'ipq_options' ); - if ( get_post_meta( $product->id, '_wpbo_deactive', true ) == 'on' ) { + if ( get_post_meta( $product->get_id(), '_wpbo_deactive', true ) == 'on' ) { return 'inactive'; - } elseif ( get_post_meta( $product->id, '_wpbo_override', true ) == 'on' ) { + } elseif ( get_post_meta( $product->get_id(), '_wpbo_override', true ) == 'on' ) { $rule = wcqu_get_applied_rule_obj( $product, $role ); $rule->rule_status = 'override'; return $rule; @@ -40,8 +40,8 @@ function wcqu_get_applied_rule( $product, $role = null ) { function wcqu_get_applied_rule_obj( $product, $role = null ) { // Get Product Terms - $product_cats = wp_get_post_terms( $product->id, 'product_cat' ); - $product_tags = wp_get_post_terms( $product->id, 'product_tag' ); + $product_cats = wp_get_post_terms( $product->get_id(), 'product_cat' ); + $product_tags = wp_get_post_terms( $product->get_id(), 'product_tag' ); // Get role if not passed if(!is_user_logged_in()) { @@ -186,13 +186,13 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { // Return Out of Stock values if they exist switch ( $type ) { case 'min': - $min_oos = get_post_meta( $product->id, '_wpbo_minimum_oos', true ); + $min_oos = get_post_meta( $product->get_id(), '_wpbo_minimum_oos', true ); if ( $min_oos != '' ) return $min_oos; break; case 'max': - $max_oos = get_post_meta( $product->id, '_wpbo_maximum_oos', true ); + $max_oos = get_post_meta( $product->get_id(), '_wpbo_maximum_oos', true ); if ( $max_oos != '' ) return $max_oos; break; @@ -203,13 +203,13 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { switch ( $type ) { case 'all': $value = array( - 'min_value' => get_post_meta( $product->id, '_wpbo_minimum', true ), - 'max_value' => get_post_meta( $product->id, '_wpbo_maximum', true ), - 'step' => get_post_meta( $product->id, '_wpbo_step', true ), - 'min_oos' => get_post_meta( $product->id, '_wpbo_minimum_oos', true ), - 'max_oos' => get_post_meta( $product->id, '_wpbo_maximum_oos', true ), - 'min_sale' => get_post_meta( $product->id, '_wpbo_minimum_sale', true ), - 'max_sale' => get_post_meta( $product->id, '_wpbo_maximum_sale', true ), + 'min_value' => get_post_meta( $product->get_id(), '_wpbo_minimum', true ), + 'max_value' => get_post_meta( $product->get_id(), '_wpbo_maximum', true ), + 'step' => get_post_meta( $product->get_id(), '_wpbo_step', true ), + 'min_oos' => get_post_meta( $product->get_id(), '_wpbo_minimum_oos', true ), + 'max_oos' => get_post_meta( $product->get_id(), '_wpbo_maximum_oos', true ), + 'min_sale' => get_post_meta( $product->get_id(), '_wpbo_minimum_sale', true ), + 'max_sale' => get_post_meta( $product->get_id(), '_wpbo_maximum_sale', true ), //'roles' => get_post_meta( $rule->ID, '_roles', true ), 'cats' => get_post_meta( $rule->ID, '_cats', true ), 'tags' => get_post_meta( $rule->ID, '_tags', true ), @@ -229,23 +229,23 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { break; case 'min': - return get_post_meta( $product->id, '_wpbo_minimum', true ); + return get_post_meta( $product->get_id(), '_wpbo_minimum', true ); break; case 'max': - return get_post_meta( $product->id, '_wpbo_maximum', true ); + return get_post_meta( $product->get_id(), '_wpbo_maximum', true ); break; case 'step': - return get_post_meta( $product->id, '_wpbo_step', true ); + return get_post_meta( $product->get_id(), '_wpbo_step', true ); break; case 'min_oos': - return get_post_meta( $product->id, '_wpbo_minimum_oos', true ); + return get_post_meta( $product->get_id(), '_wpbo_minimum_oos', true ); break; case 'max_oos': - return get_post_meta( $product->id, '_wpbo_maximum_oos', true ); + return get_post_meta( $product->get_id(), '_wpbo_maximum_oos', true ); break; case 'cats': @@ -257,11 +257,11 @@ function wcqu_get_value_from_rule( $type, $product, $rule ) { break; case 'min_sale': - return get_post_meta( $product->id, '_wpbo_minimum_sale', true ); + return get_post_meta( $product->get_id(), '_wpbo_minimum_sale', true ); break; case 'max_sale': - return get_post_meta( $product->id, '_wpbo_maximum_sale', true ); + return get_post_meta( $product->get_id(), '_wpbo_maximum_sale', true ); break; case 'priority': diff --git a/quantites-and-units.php b/quantites-and-units.php index ebbbc56..e0eaed3 100755 --- a/quantites-and-units.php +++ b/quantites-and-units.php @@ -6,6 +6,8 @@ Version: 1.0.13 Author: Nicholas Verwymeren Author URI: https://www.nickv.codes +WC requires at least: 3.0.0 +WC tested up to: 3.2.0 Text Domain: qau Domain Path: /languages */ @@ -204,10 +206,10 @@ public function input_value_validation() { if ( ! is_cart() ) { // Get the product - $pro = get_product( $post ); + $pro = wc_get_product( $post ); // Check if variable - if ( $pro->product_type == 'variable' ) { + if ( $pro->is_type( 'variable' ) ) { // See what rules are being applied $rule_result = wcqu_get_applied_rule( $pro ); diff --git a/readme.txt b/readme.txt index 7b49be8..20fa5fa 100755 --- a/readme.txt +++ b/readme.txt @@ -4,22 +4,24 @@ Tags: woocommerce, product quantities, product minimum values, product maximum v Donate link: https://www.nickv.codes/donate Requires at least: 3.5 Tested up to: 4.3 -Stable tag: 1.0.13 +Stable tag: 1.0.15 +WC requires at least: 3.0.0 +WC tested up to: 3.2.0 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html Easily require your customers to buy a minimum / maximum / incremental amount of products. Supports decimal quantities. == Description == -NOTE: This plugin has been forked from the "Advanced Product Quantities" plugin. It adds decimal quantities support and -units to products. Please don't attempt to run both plugins simultaneously. It not needed and the universe will +NOTE: This plugin has been forked from the "Advanced Product Quantities" plugin. It adds decimal quantities support and +units to products. Please don't attempt to run both plugins simultaneously. It not needed and the universe will probably implode. -With Quantities and Units for WooCommerce you can easily create rules that restrict the amount of products a user can -buy at once. Set Minimum, Maximum and Step values for any product type and must be valid before a customer can proceed +With Quantities and Units for WooCommerce you can easily create rules that restrict the amount of products a user can +buy at once. Set Minimum, Maximum and Step values for any product type and must be valid before a customer can proceed to checkout. Quantities and Units also bring decimal quantity support to WooCommerce. -This plugin works great with [Rapid Order](http://rapidorderplugin.com/), a fast ordering system for WooCommerce. +This plugin works great with [Rapid Order](http://rapidorderplugin.com/), a fast ordering system for WooCommerce. New Features @@ -47,7 +49,7 @@ Features: * Now fully supports ALL PRODUCT TYPES, simple, variable, grouped and affiliate * Create Site Wide rules that apply to every product unless overwritten on a per-product basis * Create rules by Product Tags (opposed to just categories) -* Woocommerce +2.0 compatible +* Woocommerce +2.0 compatible == Installation == @@ -70,11 +72,17 @@ Manual Installation 6. Set Rules for categories by clicking the new ‘Quantity Rules’ sidebar option or assign per-product rules by using the new metabox on your product page. == Changelog == += 1.0.15 = +* WC 3.2 compatibility + += 1.0.14 = +* Fixed an issue related to a category being deleted + = 1.0.13 = * Fixed input issue introduced in 10.0.12 release = 1.0.12 = -* Fixed an issue where sometimes the correct value would not display when using decimal quantities. +* Fixed an issue where sometimes the correct value would not display when using decimal quantities. = 1.0.11 = * Fixed issue with max value causing amount not to increment correctly in some circumstances. @@ -119,7 +127,7 @@ Manual Installation == Screenshots == 1. Single product page, page loads with it's minimum quantity and notifies the user below. -1. Create rule page. +1. Create rule page. 1. Single product 'Product Quantity Rules' meta box. Deactivate or override rules. Even set out of stock min/max values. 1. Single product 'Product Quantity Rules' meta box. Display of values by user role. 1. 'Advanced Rules' page, set sitewide rules and configure quantity notifications (screenshot 1)