golden hour
/home/godaofbq/.trash/woocompositeproduct
⬆️ Go Up
Upload
File/Folder
Size
Actions
Licensing
-
Del
OK
README.md
22 B
Del
OK
assets
-
Del
OK
extendons-composite-products.php
14.02 KB
Del
OK
extendons-composite-products.pot
13 KB
Del
OK
includes
-
Del
OK
languages
-
Del
OK
templates
-
Del
OK
Edit: extendons-composite-products.php
<?php /** * Plugin Name: Extendons Composite Products * Description: WooCommerce Composite Products plugin helps you allow customers to compose a product from different components according to their custom requirements. * Version: 1.1.1 * Author: Extendons * Author URI: https://www.extendons.com/ * Support URI: http://support.extendons.com * Text Domain: extendons-composite-products * Domain Path: /languages/ * WC requires at least: 2.6.0 **/ class EXTENDONS_COMPOSTIE_PRODUCT { public function __construct() { $this->composite_product_module_constant(); add_action( 'wp_enqueue_script', array( $this, 'wcp_main_scripts')); add_action( 'plugins_loaded', array( $this, 'wcp_loading_textdmaon' ), 100 ); require_once( cmposite_ext_dir.'includes/backoffice/extendons-composite-backend.php'); require_once( cmposite_ext_dir.'includes/frontoffice/extendons-composite-frontend.php'); // require_once( cmposite_ext_dir.'includes/functions-composite.php'); add_action( 'wp_ajax_composite_products_select', array($this,'render_all_composite_products_for_admin') ); add_action('wp_ajax_compositepro_ajax_add_component', array($this,'add_composite_products_for_admin') ); add_action('wp_ajax_compositepro_ajax_add_dependence', array($this,'compositepro_ajax_add_dependence') ); add_action('wp_ajax_compositepro_ajax_save_component', array($this, 'compositepro_ajax_save_component')); add_action('wp_ajax_get_all_component', array($this, 'get_all_component')); add_action('wp_ajax_nopriv_get_all_component', array($this, 'get_all_component')); add_action('wp_ajax_compositepro_ajax_save_Dependencies', array($this, 'compositepro_ajax_save_Dependencies')); add_action('wp_ajax_get_all_dependencies', array($this, 'get_all_dependencies')); add_action('wp_ajax_nopriv_get_all_dependencies', array($this, 'get_all_dependencies')); add_action( 'wp_ajax_composite_component_items_selected', array( $this,'component_items_selected')); add_action( 'wp_ajax_nopriv_composite_component_items_selected', array( $this,'component_items_selected')); add_action( 'wp_ajax_applyDependenciesDataOnComponent', array( $this,'applyDependenciesDataOnComponent')); add_action( 'wp_ajax_nopriv_applyDependenciesDataOnComponent', array( $this,'applyDependenciesDataOnComponent')); add_action('wp_ajax_generateVariantId', array( $this,'generateVariantId')); add_action('wp_ajax_nopriv_generateVariantId', array( $this,'generateVariantId')); } public function generateVariantId() { $match_attributes = $_POST['match_attributes']; $product_idd = $_POST['product_id']; $data_store = WC_Data_Store::load('product'); $variation_id = $data_store->find_matching_product_variation(new \WC_Product($product_idd), $match_attributes); $response_data = array( 'variation_id' => $variation_id, 'match_attributes' => $match_attributes, ); header('Content-Type: application/json'); echo json_encode($response_data); wp_die(); } public function get_all_dependencies(){ $dependencies = get_post_meta($_POST['product_id'],'_composite_dependencies_data' ,true); echo json_encode( unserialize($dependencies)); die(); } public function get_all_component(){ $dependencies = get_post_meta($_POST['product_id'],'_composite_component_data' ,true); echo json_encode ( unserialize($dependencies)); die(); } public function component_items_selected() { if( isset( $_REQUEST['master_id'] ) && isset( $_REQUEST['product_id'] ) && isset( $_REQUEST['key'] ) ) { $master_id = intval( $_REQUEST['master_id'] ); $product_id = intval( $_REQUEST['product_id'] ); if ( $product_id > 0 ) { $key = intval($_REQUEST['key']); if ($key >= 0) { $product = wc_get_product( $product_id ); // YITH_WCP_Frontend::markProductAsCompositeProcessed( $product, $master_id, $key ); ob_start(); wc_get_template( 'composite-option-items/component-selected-item.php', array( 'composite_product' => wc_get_product( $master_id ), 'product' => $product, 'key' => $key, 'post' => get_post( $product_id ), ), '', cmposite_ext_path. '/' ); $html = ob_get_clean(); $attr_wccl = function_exists( 'compsite_WCCL_Frontend' ) ? compsite_WCCL_Frontend()->create_attributes_json( $product_id, true ) : ''; wp_send_json( array( 'html' => $html, 'attr_wccl' => $attr_wccl ) ); } } } die(); } // public applyDependenciesDataOnComponent(){ // } public static function getProductsQueryArgss( $post_id , $wcp_data_single_item , $post_per_page = -1 , $current_page = 1 , $custom_order_by = 'menu_order' , $custom_order = 'asc' ) { $atts = array( 'orderby' => $custom_order_by, 'order' => $custom_order, ); $atts = apply_filters( 'compositepro_order_product_incomponent', $atts, $post_id, $wcp_data_single_item ); // // Default ordering args $ordering_args = WC()->query->get_catalog_ordering_args( $atts['orderby'], $atts['order'] ); $args = array( 'post_type' => 'product', 'posts_per_page' => $post_per_page, 'ignore_sticky_posts' => 1, 'post_status' => array( 'publish' ), 'post__not_in' => array( $post_id ), 'orderby' => $ordering_args['orderby'], 'order' => $ordering_args['order'], ); if ( isset( $ordering_args['meta_key'] ) ) { $args['meta_key'] = $ordering_args['meta_key']; } if ( apply_filters( 'compositepro_hide_outofstock_components', false ) ) { $args['meta_query']['stock_status'] = array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => 'NOT IN' ); } if ( $post_per_page > 0 ) { $args['paged'] = $current_page; } switch ( $wcp_data_single_item['option_type'] ) { case 'product' : $ids = is_array( $wcp_data_single_item['option_type_product'] ) ? $wcp_data_single_item['option_type_product'] : explode( ',', $wcp_data_single_item['option_type_product'] ); $ids = array_map( 'trim', $ids ); $args['post__in'] = $ids; break; case 'product_categories' : $args['product_cat'] = implode( ',', $wcp_data_single_item['option_type_category'] ); break; case 'product_tags' : $args['product_tag'] = implode( ',', $wcp_data_single_item['option_type_tags'] ); break; } return $args; } public function compositepro_ajax_save_Dependencies() { if (isset($_POST['condition']) && $_POST['condition'] == "ajaxSaveDependence") { $post_id = absint( $_POST[ 'post_id' ] ); parse_str( $_POST['dependenceAjaxSave'], $cData ); print_r($cData); if (!empty($cData['_composite_dependence_data'])) { $dependence_data = ($cData['_composite_dependence_data']); $wcp_dependence_data = isset( $dependence_data ) ? $dependence_data : false; $wcp_dependence_datas = array_values($wcp_dependence_data); } else { $wcp_dependence_datas = ''; } update_post_meta($post_id, '_composite_dependencies_data', serialize($wcp_dependence_datas)); die(); } } public function compositepro_ajax_save_component() { // error_reporting(E_ALL); //ini_set("display_errors", 1); if(isset($_POST['condition']) && $_POST['condition'] == "ajaxSaveComponent") { $post_id = absint( $_POST[ 'post_id' ] ); // getting the data ad parse string parse_str( $_POST['componenetAjaxSave'], $cData ); // make parse string as array if (!empty($cData['_composite_component_data'])) { $compositeData = $cData['_composite_component_data']; $wcp_composite_data = isset( $compositeData ) ? $compositeData : false; $wcp_composite_datas = array_values($wcp_composite_data); } else { $wcp_composite_datas = ''; } update_post_meta($post_id, '_composite_component_data', serialize($wcp_composite_datas)); // update_post_meta( $post_id, 'test', 'scndtym'); wp_send_json_success(); } die(); } public function add_composite_products_for_admin() { $post_id = absint( $_POST[ 'post_id' ] ); $itemcount = absint( $_POST[ 'itemcount' ] ); $this->composite_list_options_sigle( '' , array() , $post_id, $itemcount ); die(); } public function compositepro_ajax_add_dependence(){ $post_id = absint( $_POST[ 'post_id' ] ); $itemcount = absint( $_POST[ 'itemcount' ] ); $this->dependence_list_options_sigle( '' , array() , $post_id, $itemcount ); die(); } public function dependence_list_options_sigle( $wcp_data_key , $wcp_data_single_item, $post_id, $itemcount ) { include( cmposite_ext_dir . 'includes/backoffice-views/dependencies-list-form-view.php' ); } public function composite_list_options_sigle( $wcp_data_key , $wcp_data_single_item, $post_id, $itemcount ) { include( cmposite_ext_dir . 'includes/backoffice-views/composite-list-form-view.php' ); } // public function render_all_composite_products_for_admin() { // // we will pass post IDs and titles to this array // $return = array(); // $search_results = new WP_Query( array( // 's'=> $_GET['q'], // 'post_status' => 'publish', // 'ignore_sticky_posts' => 1, // 'posts_per_page' => -1, // 'post_type' => 'product', // 'post__not_in' => array($_GET['ide']), // 'orderby' => 'menu_order', // 'order' => 'asc', // ) ); // if( $search_results->have_posts() ) : // while( $search_results->have_posts() ) : $search_results->the_post(); // $title = ( mb_strlen( $search_results->post->post_title ) > 50 ) ? mb_substr( $search_results->post->post_title, 0, 49 ) . '...' : $search_results->post->post_title; // $return[] = array( $search_results->post->ID, $title ); // endwhile; // endif; // echo json_encode( $return ); // die; // } public function render_all_composite_products_for_admin() { // we will pass post IDs and titles to this array $return = array(); $search_results = new WP_Query( array( 's'=> $_GET['q'], 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'post_type' => 'product', 'post__not_in' => array($_GET['ide']), 'orderby' => 'menu_order', 'order' => 'asc', 'tax_query' => array( 'relation' => 'AND', array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => array( 'grouped', 'external', 'affiliate' ), 'operator' => 'NOT IN', ), ), ) ); if( $search_results->have_posts() ) : while( $search_results->have_posts() ) : $search_results->the_post(); $title = ( mb_strlen( $search_results->post->post_title ) > 50 ) ? mb_substr( $search_results->post->post_title, 0, 49 ) . '...' : $search_results->post->post_title; $return[] = array( $search_results->post->ID, $title ); endwhile; endif; echo json_encode( $return ); die; } // module constant public function composite_product_module_constant() { if ( !defined( 'cmposite_ext_url' ) ) define( 'cmposite_ext_url', plugin_dir_url( __FILE__ ) ); if ( !defined( 'cmposite_ext_basename' ) ) define( 'cmposite_ext_basename', plugin_basename( __FILE__ ) ); if ( ! defined( 'cmposite_ext_dir' ) ) define( 'cmposite_ext_dir', plugin_dir_path( __FILE__ ) ); if ( !defined( 'cmposite_ext_path' ) ) define( 'cmposite_ext_path', cmposite_ext_dir . 'templates' ); } // loading text domain public function wcp_loading_textdmaon() { load_plugin_textdomain( 'extendons-composite-products', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } //enqueue the scripts and css public function wcp_main_scripts() { wp_enqueue_script('jquery'); // wp_enqueue_script('select2-jq','https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'); // wp_enqueue_script('select2-js', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0-beta.1/js/select2.min.js'); // wp_enqueue_script( 'compositepro-backend-script', plugins_url( '../../assets/js/backend.js', __FILE__ ), false ); } } new EXTENDONS_COMPOSTIE_PRODUCT(); add_action('wp_head', 'aaaaa'); add_action('wp_footer', 'aaaaa'); function aaaaa() { wp_enqueue_script( 'wc-add-to-cart-variation'); }
Save