WC marketplace integration
-
Hi
I want to contribute by these codes that integrate this plugin with WC Marketplace
https://www.ads-software.com/plugins/dc-woocommerce-multi-vendor/File 1:
includes/class-mepu-woo.php
After line n°: 178, add this
$this->loader->add_action('wp_enqueue_scripts', $plugin, 'enqueue_scripts');
File 2:
frontend/class-mepu-woo-frontend.php
After line n°: 150, add this
/** * Register the JavaScript for the dc-marketplace vendor dashboard. * * @since 1.0.0 */ public function enqueue_scripts() // to be complete { // dc-marketplace scripts integration if(class_exists('WCMp')){ wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/mepu-woo-dc-dashboard.js', array('jquery'), $this->version, false); } }
File 3:
Create new file with this path:
frontend/js/mepu-woo-dc-dashboard.js
The content:
(function ($) { 'use strict'; $('#woocommerce-product-data').ready(function (event) { if ($('.mepu-woo-cont').length) { if ($('#mepu-woo-data').val() != '') { var data = $.parseJSON($('#mepu-woo-data').val()); if (data[0] != undefined) { for (var i = 0; i < data[0].length; i++) { mepu_woo_clone_block(i, data[0][i]); } } } $('.mepu-woo-add').bind('click', function () { mepu_woo_clone_block($('.mepu-woo-cont-item').length, ['', '']); }); } }); function mepu_woo_clone_block(i, data) { var new_block = $('.mepu-woo-only-for-clone').clone(); new_block.removeClass('hidden').removeClass('mepu-woo-only-for-clone').addClass('mepu-woo-cont-item'); new_block.find('h5').html(new_block.find('h5').html().replace('##', '#' + (i + 1))); new_block.find('label').each(function () { $(this).html($(this).html().replace('##', '#' + (i + 1))); }); var input_iterator = 0; new_block.find('input').each(function () { $(this).val(data[input_iterator++]); if ($(this).attr('id') == '_product_url_clone_[]') { $(this).attr('id', '_product_url_[]'); $(this).attr('name', '_product_url_[]'); } if ($(this).attr('id') == '_button_text_clone_[]') { $(this).attr('id', '_button_text_[]'); $(this).attr('name', '_button_text_[]'); } }); $('.mepu-woo-cont').append(new_block); mepu_bind_block_actions(); } function mepu_bind_block_actions() { $(".mepu-woo-delete").on('click', function () { $(this).closest('.mepu-woo-cont-item').remove(); }); } })(jQuery);
File 4:
admin/class-mepu-woo-additional-fields.php
After line n°: 60 , add this
// dc-marketplace integration if (class_exists('WCMp')) { add_action('wcmp_afm_after_general_product_data', array($this, 'wcmp_frontend_mepu_extra_fields'), 10, 3); add_action('wcmp_process_product_object', array($this, 'wcmp_frontend_mepu_extra_fields_process'), 10, 2); }
After line n°: 166, add this
/** * Display extra fields clone container, display json array with multiple external details in wc marketplace * * @since 1.0.0 */ function wcmp_frontend_mepu_extra_fields($pro_class_obj, $product, $post_data) { global $post; $multiple_external_fields = get_post_meta($post_data->ID, '_multiple_external_'); if (empty($multiple_external_fields) || !is_array($multiple_external_fields)) { $multiple_external_fields = array(); } // hidden in put echo '<div class="form-group"><div class="col">'; echo "<input type='hidden' value='" . json_encode($multiple_external_fields, JSON_HEX_APOS) . "' id='mepu-woo-data'>"; echo '</div></div>'; echo '<div class="options_group show_if_external mepu-woo-cont" style="padding:0px 10px;">'; // add new urls section echo '<div class="form-group"> <div class="col col"> <h4>' . __('Multiple external product URLs', 'mepu-woo') . '- <a href="#mepu-woo-data" class="mepu-woo-add">' . __('Add new', 'mepu-woo') . '</a></h4> </div> </div>'; // extra urls options echo '<div class="form-group"> <label class="control-label col-sm-3 col-md-3" for="_external_target_blank">' . __('Open in new tab', 'mepu-woo') . '</label> <div class="col-md-6 col-sm-9"> <input type="checkbox" class="checkbox" style="" name="_external_target_blank" id="_external_target_blank" value="yes"> ' . __('Open external / affiliate URLs in new tab?', 'mepu-woo') . ' </div> </div>'; echo '<div class="form-group"> <label class="control-label col-sm-3 col-md-3" for="_external_show_in_cat">' . __('Category pages', 'mepu-woo') . '</label> <div class="col-md-6 col-sm-9"> <input type="checkbox" class="checkbox" style="" name="_external_show_in_cat" id="_external_show_in_cat" value="yes"> ' . __('Show all external product buttons on category pages', 'mepu-woo') . ' </div> </div>'; // extra urls sections echo '<div class="hidden mepu-woo-only-for-clone" style="border-bottom:1px solid #efefef;">'; echo ' <div class="form-group"> <div class="col col"> <h5>' . __('## External / Affiliate product details', 'mepu-woo') . ' - <a href="#mepu-woo-data" class="mepu-woo-delete">' . __('Delete', 'mepu-woo') . '</a></h5> </div> </div>'; echo ' <div class="form-group"> <label class="control-label col-sm-3 col-md-3" for="_product_url_clone_[]">' . __('Product URL ##', 'mepu-woo') . '</label> <div class="col-md-6 col-sm-9"> <input type="text" class="short" style="" name="_product_url_clone_[]" id="_product_url_clone_[]" value="" placeholder="https://"> </div> </div>'; echo ' <div class="form-group"> <label class="control-label col-sm-3 col-md-3" for="_button_text_clone_[]">' . __('Button text ##', 'mepu-woo') . '</label> <div class="col-md-6 col-sm-9"> <input type="text" class="short" style="" name="_button_text_clone_[]" id="_button_text_clone_[]" value="" placeholder="Buy product"> </div> </div>'; echo '</div>'; echo '</div>'; } /** * Update wcmp product meta "_multiple_external_" on save * * @param array $product - product info * @param array $post_data - product meta * @since 1.0.0 * * @return mixed */ function wcmp_frontend_mepu_extra_fields_process($product, $post_data) { $fine_array = array(); if (!( isset($post_data['wcmp_product_nonce'], $post_data['_external_target_blank'], $post_data['_product_url_'], $post_data['_button_text_']) || wp_verify_nonce($post_data['wcmp_product_nonce'], 'wcmp-product') )) { return false; } for ($i = 0; $i < count($post_data['_product_url_']); $i++) { if (isset($post_data['_product_url_'][$i], $_POST['_button_text_'][$i])) { if (!empty($post_data['_product_url_'][$i]) && !empty($post_data['_button_text_'][$i])) { array_push($fine_array, array($post_data['_product_url_'][$i], $post_data['_button_text_'][$i])); } } } update_post_meta( $post_data['post_ID'], '_multiple_external_', $fine_array ); update_post_meta( $post_data['post_ID'], '_external_target_blank', esc_attr($post_data['_external_target_blank']) ); update_post_meta( $post_data['post_ID'], '_external_show_in_cat', esc_attr($post_data['_external_show_in_cat']) ); }
That’s all
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘WC marketplace integration’ is closed to new replies.