close
Kaspersky Endpoint Security

Welcome to

Kaspersky Endpoint Security


By Kaspersky Endpoint Security


WooCommerce Produktanbieter - Hinzufügen Frontend Management Dashboard



Für die Zwecke dieses Artikels in der Haupt werde ich zeigen Ihnen, wie ich ein Dashboard hinzugefügt Buchungen verwalten verkauft das Plugin WooCommerce Buchungen mit über das WooCommerce Produktanbieter-Plugin, denn das ist das, was ich den Code für vor kurzem tat und so ist es alles verpackt up schön und ordentlich und alles getestet wie. Allerdings könnte es leicht Produkte verwendet werden, um zu verwalten von anderen Erweiterungen, und auch andere Optionen wie Versand usw. aus dem gleichen Ort.

Ich habe den Code für diese zu einem Gist hinzugefügt - so wenden Sie sich bitte dort überprüfen.

Nun - ich bauen meine WooCommerce Erweiterungen einen Rahmen meiner eigenen Schöpfung verwenden, und der erste Schritt in diesem Rahmen ist die Funktion nur ausgeführt werden, wenn die Plugins es muss aktiv sind:

In diesem Fall müssen wir WooCommerce, WooCommerce Produktanbieter und WooCommere Buchungen der so heraus finden lassen, wenn wir sie haben:

Klasse WVBM {    private $ Textdomain = "WooCommerce-Anbieter-Buchungen-Management";    private $ required_plugins = array ( 'WooCommerce', 'WooCommerce-Buchungen "," WooCommerce-Produkt-Anbieter');    Funktion have_required_plugins () {        $ Active_plugins = (Array) get_option ( 'active_plugins', array ());        if (is_multisite ()) {            $ Active_plugins = array_merge ($ active_plugins, get_site_option ( 'active_sitewide_plugins', array ()));        }        foreach ($ this-> required_plugins als $ key => $ erforderlich) {            $ Erforderlich = (! Is_numeric ($ key))? "{$ Key} / {erforderlich $} .php": "{$ erforderlich} / {erforderlich $} .php";            if (! in_array ($ erforderlich, $ active_plugins) &&! array_key_exists ($ erforderlich, $ active_plugins))                return false;        }        return true;    }    Funktion __construct () {        if (! $ this-> have_required_plugins ())            Rückkehr;    }

So wie Sie speichern wir die drei Plugin Namen auf ein Array sehen können, sammelt die have_required_plugins Funktion dann alle Orte, wo aktivierten Plugins gespeichert sind, und prüft, ob die erforderlichen diejenigen. Hinweis aktiven Plugins sind mit ihren folder / Dateiname gespeichert - in den meisten Fällen beide sind die gleichen, aber wenn man über einen kommen, wo der Dateiname anders ist dann nur speichern es als Schlüssel => Wert Element wie:

private $ required_plugins = array ( 'WooCommerce', 'WooCommerce-Buchungen' => 'woo-Buchungen "," WooCommerce-Produkt-Anbieter');

Der Code in have_required_plugins ist bereit, solche Fälle zu behandeln.

Nun - wir werden unseren Lieferanten Armaturenbrett auf seine eigene URL zu haben - / Lieferanten-Armaturenbrett. Es gibt eine einfache Möglichkeit, dies zu tun: einfach eine Seite hinzufügen und führen dann das Dashboard-Code über eine Kurzwahlnummer. Aber wir wollen es die neue glänzende coole Art zu tun, die einen benutzerdefinierten Endpunkt hinzufügt.

Um dies zu tun, haben Sie die neue Abfrage var in die Menge zu registrieren (Satz existiert, ist Dinge wie 'Seite', 'post' usw.), haben Sie die neue Abfrage var als Endpunkt zu registrieren, und dann behandeln die Verarbeitung von Code, wenn jemand den Endpunkt (uRL) besucht. Das Hinzufügen von neuen Regeln für das Umschreiben zu Wordpress bedeutet auch, müssen Sie das System spülen.

Der beste Weg, die ich gefunden habe den Endpunkt und Rewrite-Regeln hinzuzufügen, ist es bei der Aktivierung Ihres Plugins zu tun.

register_activation_hook (__ FILE__, array ($ this, 'rewrite_flush'));Funktion rewrite_flush () {                flush_rewrite_rules ();    }

Also auf die Anfrage var des Endpunkts registrieren:

add_filter ( 'query_vars', array ($ this, 'add_query_vars'));Funktion add_query_vars ($ vars) {        $ Vars [] = "Anbieter-Armaturenbrett ';        return $ vars;    }

Jetzt auf init fügen wir unseren Endpunkt:

add_action ( 'init', array ($ this, 'endpoint_keeper'));Funktion endpoint_keeper () {         add_rewrite_endpoint ( "Anbieter-Armaturenbrett", EP_ALL);         add_rewrite_rule('/vendors-dashboard/(.*)/page/([0-9]+)\/?','index.php?vendors-dashboard=$matches[1]&paged=$matches[2]','top');    }

Jetzt behandeln die Anfragen für unsere Endpunkt (eine Anforderung ist, was auf dem Server vorgenommen wird, um den Inhalt für eine bestimmte URL zu erhalten).

add_action ( 'parse_request', array ($ this, 'parse_request'), 0);Funktion parse_request ($ request) {        global $ wp;        $ Key = 'Anbieter-Armaturenbrett';    if (isset ($ _GET [$ key])) {            $ WP-> query_vars [$ key] = $ _GET [$ key];    }    wenn sonst (isset ($ WP-> query_vars [$ key])) {            $ WP-> query_vars [$ key] = $ WP-> query_vars [$ key];    }    }

Wir prüfen nur, wenn wir unsere Endpunkt dienen, und wenn wir die Abfrage var in das $ wp Array bauen. Wir verwenden diese Abfrage dann var zu prüfen, ob wir auf unserer Seite und dient unsere eigene Inhalte wie so sind:

add_filter ( 'template_include', array ($ this, 'get_template')); Funktion get_template ($ template) {        global $ wp;        if (isset ($ WP-> query_vars [ 'Anbieter-Armaturenbrett']))            $ Template = trailingslashit (plugin_dir_path (__ FILE__)). "Anbieter-dashboard.php";        return $ Vorlage;    }

Die einzige andere Sache, die wir in unsere Datei tun, ist für die Verarbeitung der Aktion der Bestätigung der Buchung eine Funktion Haken - ich Ajax für diese verwendet haben könnte, aber wählte PHP zu verwenden:

add_action ( 'wp', array ($ this, 'process_confirm'));Funktion process_confirm () {        if ($ _GET [ 'wvbm_action'] == "bestätigen") {            if (get_post_type ($ _ GET [ 'booking_id'])! = "wc_booking" ||! wp_verify_nonce ($ _ REQUEST [ 'Sicherheit'], 'Vendor-Buchungs-confirm-noncerator')) {                wc_add_notice ( "Ungültige Anfrage - Buchung nicht bestätigt", "Fehler");                $ Url = site_url (). "/vendors-dashboard/".get_query_var('vendors-dashboard')."/";                header (. "Location:" $ url);            }            $ Buchung = new WC_Booking ($ _ GET [ 'booking_id']);            $ Buchung-> update_status ( "bestätigt");            wc_add_notice ( "Buchung" $ _ GET [ 'booking_id'] "bestätigt", "Erfolg"..);        }    }

Jetzt auf der Anbieter-dashboard.php Vorlage:

<? Phpget_header ();global $ WVBM;?> <Div id = "content" class = "WooCommerce Container">        <Div class = "Reihe Produkt-Content-Bereich">            <Haupt id = "main" class = "site-main col-xl-12" role = "main"><? Php $ WVBM-> show_dashboard (); ?></ Main>
<?php get_footer(); ?>

Note two key parts here:

global $WVBM
  • this is the global we have stored the main plugin class into, and bringing it in allows us to use the biggest function from that class:
$WVBM->show_dashboard();
function show_dashboard() {        /* extract(shortcode_atts(array(          'active_tabs' => 'bookings'//comma seperated list of active tabs          ),$atts)); */        $vendor = get_term_by('slug',get_query_var('vendors-dashboard'),'shop_vendor');        if (!$vendor) {            echo "

Vendor not found!

"; return; } $user = get_current_user_id(); if (!current_user_can('administrator') && !is_vendor_admin($vendor->term_id,$user)) { echo "

You do not have permission to view this page

"; return; } $cols = array('Booking ID', 'Parent Order', 'Date', 'Start Time', 'End Time', '# of Guests', 'Price', 'User', 'Date Applied', 'Status','Actions'); $tabs = array('bookings'); $posts_per_page = 10; $page = (get_query_var('paged')) ? 1 : get_query_var('paged'); $bookings = new WP_Query(array( 'post_type' => 'wc_booking', 'posts_per_page' => $posts_per_page, 'meta_key' => '_booking_vendor', 'meta_value' => $vendor->term_id, 'post_status' => 'any', 'paged' => get_query_var('paged') )); $data = array(); foreach($bookings->posts as $key => $booking) { $_booking = new WC_Booking($booking->ID); $user = get_post_meta($booking->ID,'_booking_customer_id',true); $actions = array(); if ($booking->post_status != "cancelled") array_push($actions,"cancel"); if ($booking->post_status == "pending-confirmation") array_push($actions,"confirm"); $action_strings = array(); foreach($actions as $action) { $action_url = add_query_arg(array('wvbm_action'=>$action,'booking_id'=>$booking->ID,'security'=>wp_create_nonce('vendor-booking-confirm-noncerator')),site_url()."/vendors-dashboard/".get_query_var('vendors-dashboard')."/"); $action_strings[] = ($action == "cancel") ? "" : ""; } $data[$booking->ID] = array( 'Booking ID' => $booking->ID, 'Parent Order' => $booking->post_parent, 'Date' => date("Y-m-d",strtotime(get_post_meta($booking->ID,'_booking_start',true))), 'Start Time' => date("h:ia",strtotime(get_post_meta($booking->ID,'_booking_start',true))), 'End Time' => date("h:ia",strtotime(get_post_meta($booking->ID,'_booking_end',true))), '# of Guests' => count(get_post_meta($booking->ID,'_booking_persons',true)), 'Price' => get_post_meta($booking->ID,'_booking_cost',true), 'User' => (get_user_meta($user,'billing_first_name',true) !== "") ? get_user_meta($user,'billing_first_name',true) . " " . get_user_meta($user,'billing_last_name',true) : $user->user_login, 'Date Applied' => $booking->post_date, 'Status' => $booking->post_status, 'Actions' => implode(" | ",$action_strings) ); } wc_print_notices(); ?><div class="woocommerce-tabs"> <ul class="tabs"> <?php foreach ($tabs as $key => $tab) { $class = ($key == 0) ? "active" : ""; ?><li class="dashboard_tab $tab) { ?><div class="panel entry-content" id="tab-<?php echo $tab; ?>" style="display: block;"> <table class="<?php echo $tab; ?>-table"> <thead> <tr> <?php foreach ($cols as $key => $col) { ?> <th><?php echo $col; ?></th><?php } ?> </tr> </thead> <tbody> <?php foreach ($data as $booking_id => $booking) { ?> <tr><?php foreach($cols as $key => $col) { ?> <td><?php echo $booking[$col]; ?></td> <?php } ?> </tr><?php } ?> </tbody> </table> <?php } $big = 999999999; // need an unlikely integerecho paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $bookings->max_num_pages) );?> <?php }

That is pretty straightforward stuff, it pulls up the bookings for that vendor’s products and displays them in a html table complete with links for cancelling and confirming the booking. Simples…

Spread the love
  •  
  •  
  •  
  •  

Kaspersky Endpoint Security 2014     Endpoint-Security 2015

Categories and tags