function soya_wp_check_input($term_id)
{
    $term = get_term($term_id, 'soya-range');
    $term_depth = soya_get_term_custom_field($term_id, 'soya_depth_meta');
    //$options = soya_get_term_range($term_id, $term_depth);
    echo '<label>' . $term->name . ' ' . edit_term_link('edit ' . $term->name, '', '', $term, false) . '</label><br>';
    for ($index = 1; $index <= $term_depth; $index++) {
        echo '<input type="checkbox" name="' . $term->slug . '_' . $index . '[]" value="" id="' . $term->slug . '_' . $index . '">';
    }
}
Esempio n. 2
0
function delete_meta_fields_not_needed($object_id, $tt_id)
{
    // if (get_post_type($object_id) === 'soya_feature' && (is_tax('soya-range', $tt_id))){
    $term = get_term($tt_id);
    $term_slug = $term->slug;
    $term_meta_key = $term_slug . '_' . $tt_id;
    if (soya_is_term_child($tt_id)) {
        $term_parent_id = soya_get_term_parent_id($tt_id);
        $parent_term_slug = get_term($term_parent_id);
        $parent_term_depth = soya_get_term_custom_field($term_parent_id, 'soya_depth_meta');
        for ($i = 1; $i <= $parent_term_depth; $i++) {
            delete_post_meta($object_id, $i . '_' . $term_meta_key . '-' . $parent_term_slug . '_' . $term_parent_id);
        }
        // $term_meta_key =
        //  }else{
        delete_post_meta($object_id, 'silicone-effect_200-400');
        // }
    }
}
 public function get_parent_ranges($term_id)
 {
     if (!soya_is_term_child($term_id)) {
         return false;
     }
     $ranges = [];
     $parent_term_id = soya_get_term_parent_id($term_id);
     $depth = soya_get_term_custom_field($parent_term_id, 'soya_depth_meta');
     for ($i = 1; $i <= $depth; $i++) {
         $lower = soya_get_term_custom_field($parent_term_id, 'soya_lower_' . $i . '_depth_meta');
         $upper = soya_get_term_custom_field($parent_term_id, 'soya_upper_' . $i . '_depth_meta');
         $ranges[$lower] = !empty($lower && $upper) ? $lower . '-' . $upper : 0;
     }
     return $ranges;
     //return $this->default_qty;
 }
Esempio n. 4
0
function soya_get_meta_keys_by_range($term_id, array $ranges)
{
    $meta_keys = [];
    $term = get_term($term_id, 'soya-range');
    $term_children = get_term_children($term_id, 'soya-range');
    if (!empty($term_children)) {
        foreach ($term_children as $child_term_id) {
            $child_term = get_term($child_term_id, 'soya-range');
            $child_term_depth = soya_get_term_custom_field($child_term_id, 'soya_depth_meta');
            for ($i = 1; $i <= $child_term_depth; $i++) {
                foreach ($ranges as $range) {
                    $meta_keys[] = $i . '-' . $child_term->slug . '-' . $term->slug . '_' . $range;
                }
            }
        }
    } else {
        // for non-child parent term
        foreach ($ranges as $range) {
            $meta_keys[] = $term->slug . '_' . $range;
        }
    }
    return $meta_keys;
}
/**
 * When the post is saved, saves our custom data.
 *
 * @param int $post_id The ID of the post being saved.
 */
function soya_save_meta_box_data($post_id)
{
    /*
     * We need to verify this came from our screen and with proper authorization,
     * because the save_post action can be triggered at other times.
     */
    // Check if our nonce is set.
    if (!isset($_POST['soya_meta_box_nonce'])) {
        return;
    }
    // Verify that the nonce is valid.
    if (!wp_verify_nonce($_POST['soya_meta_box_nonce'], 'soya_meta_box')) {
        return;
    }
    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    // Check the user's permissions.
    if (isset($_POST['soya_feature']) && 'page' == $_POST['soya_feature']) {
        if (!current_user_can('edit_page', $post_id)) {
            return;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return;
        }
    }
    /* OK, it's safe for us to save the data now. */
    // Make sure that it is set.
    // get post terms ids
    $post_terms_ids = soya_get_post_terms_ids($post_id);
    //set up all post terms ranges
    $parent_post_terms_ranges = [];
    $child_post_terms_ranges = [];
    if (isset($post_terms_ids)) {
        foreach ($post_terms_ids as $post_term_id) {
            if (soya_is_term_child($post_term_id)) {
                // We want only parents ranges and slugs.
                $child_term_parent_id = esc_attr(soya_get_term_parent_id($post_term_id));
                $post_term_range = soya_loop_term_depth($child_term_parent_id);
                $post_child_term = get_term($post_term_id, 'soya-range');
                // $post_term_depth = count($post_term_range);
                $post_term_depth = soya_get_term_custom_field($post_term_id, 'soya_depth_meta');
                $post_term_slug = $post_child_term->slug;
                $post_term_range['depth'] = $post_term_depth;
                $post_term_range['slug'] = $post_term_slug;
                $child_post_terms_ranges[] = $post_term_range;
            } else {
                $post_term_range = soya_loop_term_depth($post_term_id);
                $parent_post_terms_ranges[] = $post_term_range;
            }
        }
    }
    //get keys from post terms ranges
    $all_meta_keys = [];
    $index = '';
    //Iterate for parent meta keys
    if (isset($parent_post_terms_ranges)) {
        foreach ($parent_post_terms_ranges as $post_term_range) {
            foreach ($post_term_range as $key => $label) {
                $all_meta_keys[] = $key;
            }
        }
    }
    // Build meta keys for child terms
    if (isset($child_post_terms_ranges)) {
        //$index = '';
        // $slug = '';
        foreach ($child_post_terms_ranges as $index => $post_term_range) {
            //get Depth and slug for each child term
            $indexi = $post_term_range['depth'];
            $post_child_term_slug = $post_term_range['slug'];
            // loop through each term's depth and get indices for meta keys
            for ($i = 1; $i <= $indexi; $i++) {
                //remove slug and depth from range arrange
                unset($post_term_range['slug']);
                unset($post_term_range['depth']);
                foreach ($post_term_range as $key => $label) {
                    // if($key != 'slug'):
                    $all_meta_keys[] = $i . '-' . $post_child_term_slug . '-' . $key;
                    // check for added fixed meta fields and save them too
                    if (has_action('soya_add_extra_meta_fields_' . $post_child_term_slug)) {
                        $all_meta_keys[] = $i . '-' . 'fixed-cost-' . $post_child_term_slug;
                    }
                }
            }
        }
    }
    // Apply filters
    $all_meta_keys = apply_filters('soya_filter_meta_keys', $all_meta_keys, $post_terms_ids);
    // Sanitize user input.
    foreach ($all_meta_keys as $key) {
        //check for data
        if (isset($_POST[$key])) {
            $value = sanitize_text_field($_POST[$key]);
        }
        update_post_meta($post_id, $key, $value);
    }
    //Check if a meta key is relevant and delete them
    $before_post_update_post_meta_keys = $_SESSION['post_terms'];
    $unwanted_meta_keys = array_diff($before_post_update_post_meta_keys, $all_meta_keys);
    foreach ($unwanted_meta_keys as $meta_key) {
        delete_post_meta($post_id, $meta_key);
    }
    unset($_SESSION['post_terms']);
}
function soya_add_features_to_product_page()
{
    global $product, $post;
    //make sure we are on soya variable product only
    if (!$product->is_type('soya_variable')) {
        return;
    }
    $features_id = get_post_meta($post->ID, '_soya_features', true);
    if ($features_id === 'none') {
        return;
    }
    // get post range terms
    $features_terms = wp_get_object_terms($features_id, 'soya-range', array('orderby' => 'term_id'));
    if (is_array($features_terms)) {
        echo '<ul class="features">';
        foreach ($features_terms as $index => $term) {
            $field_type = soya_get_term_custom_field($term->term_id, 'soya_display_type_meta');
            echo '<li>';
            soya_get_term_options($term->term_id, $field_type);
            echo '</li>';
        }
        echo '</ul>';
    }
    // global $product;
    // $cp = new WC_Product_Soya_Variable($product);
    //$product->set_regular_price(65);
    $product->all_features->set_quantity(400);
    $product->all_features->update_feature_meta(64, 1);
    $product->all_features->update_feature_meta(57, 1);
    $product->all_features->update_feature_meta(58, 1);
    $product->all_features->set_total_features_price();
    echo '<pre>';
    var_dump($product);
    echo '</pre>';
}