Design · PHP · Server

Design · PHP · Server

WordPress · Drupal · PrestaShop

  • Startseite
  • WordPress
  • PHP / Datenbanken
  • Ubuntu
  • Prestashop
  • Grafik
  • Glossar

WordPress: Auf der Startseite nur die Artikel einer bestimmten Kategorie listen

29. August 2015 Leave a Comment

Wenn auf der Startseite nur die Artikel einer (oder auch mehrerer ausgewählter) Kategorien gelistet werden sollen, hilft folgender Code in der functions.php

function my_home_category( $query ) { 
if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '11'); } } 
add_action( 'pre_get_posts', 'my_home_category' );

Wichtig ist hierbei der Teil $query->set( ‚cat‘, ’11‘);

Die Zahl gibt die ID der gewünschten Kategorie an. Mehrere Kategorien können mit einem Komma getrennt hintereinander aufgelistet werden, also z.B. $query->set( ‚cat‘, ‚3,5,11‘);

Filed Under: WordPress Tagged With: Startseite, WordPress

WordPress: img Attribute height and width entfernen

26. Juli 2014 Leave a Comment

Die folgenden Codezeilen in der functions.php verhindern das automatische Einfügen von den height and width Angaben eines Bildes:

add_filter( 'post_thumbnail_html', 'remove_wps_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_wps_width_attribute', 10 );
function remove_wps_width_attribute( $html ) {
    $html = preg_replace( '/(width|height)="d*"s/', "", $html );
    return $html;
}

Quelle: wpsnipp.com

Filed Under: WordPress Tagged With: WordPress

AWD Shipping Plugin für WooCommerce 2.1

6. März 2014 Leave a Comment

Für die WooCommerce Version 2.X funktioniert das AWS Shipping Plugin aus dem WordPress Repository leider nicht mehr. Im Forum auf wordpress.org hat jemand das Plugin AWD Shipping Costs mit dem funktionierenden Weight Based Shipping Plugin angepasst, so dass es auch mit WooCommerce 2.1 funktioniert. Hier sind die Änderungen

<?php
/**
 * Plugin Name: Weight and Country Table Rate shipping for Woocommerce
 * Description: WCTR is a weight and country based shipping method for Woocommerce 2.1, based on <a href="http://www.andyswebdesign.ie/blog/free-woocommerce-weight-and-country-based-shipping-extension-plugin/">AWD</a> and <a href="http://wordpress.org/plugins/weight-based-shipping-for-woocommerce/">WOOWBS</a>
 * Version: 1.0
 * Author:
 */
/*  Copyright 2012  

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

add_action( 'plugins_loaded', 'init_woowctr', 0 );

function init_woowctr() {

	if ( ! class_exists( 'WC_Shipping_Method' ) ) return;

	class WCTR_Shipping extends WC_Shipping_Method {

		function __construct() {
			$this->id           = 'WCTR_Shipping';
			$this->method_title = __( 'Table Rate', 'woocommerce' );

			$this->admin_page_heading     = __( 'Weight and country based shipping', 'woocommerce' );
			$this->admin_page_description = __( 'Define shipping by weight and country', 'woocommerce' );

			add_action( 'woocommerce_update_options_shipping_' . $this->id, array( &$this, 'process_admin_options' ) );

			$this->init();
			$this->display_country_groups();
		}

		function init() {
			$this->init_form_fields();
			$this->init_settings();

			$this->enabled          = $this->get_option('enabled');
			$this->title            = $this->get_option('title');
            $this->availability     = 'specific';
			$this->country_group_no	= $this->get_option('country_group_no');
            $this->countries 	    = $this->get_option('countries');
			$this->type             = 'order';
			$this->tax_status       = $this->get_option('tax_status');
			$this->fee              = $this->get_option('fee');
			$this->rate			= isset( $this->settings['rate'] ) ? $this->settings['rate'] : '';
			$this->rate			= (array) explode( "n", $this->rate );

            if (empty($this->countries)) {
                $this->availability = $this->settings['availability'] = 'all';
            }
		}

		function init_form_fields() {

            $woocommerce = function_exists('WC') ? WC() : $GLOBALS['woocommerce'];

			$this->form_fields = array(
				'enabled'    => array(
					'title'   => __( 'Enable/Disable', 'woocommerce' ),
					'type'    => 'checkbox',
					'label'   => __( 'Enable this shipping method', 'woocommerce' ),
					'default' => 'no',
				),
				'title'      => array(
					'title'       => __( 'Method Title', 'woocommerce' ),
					'type'        => 'text',
					'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
					'default'     => __( 'Regular Shipping', 'woocommerce' ),
				),
				'tax_status' => array(
					'title'       => __( 'Tax Status', 'woocommerce' ),
					'type'        => 'select',
					'description' => '',
					'default'     => 'taxable',
					'options'     => array(
						'taxable' => __( 'Taxable', 'woocommerce' ),
						'none'    => __( 'None', 'woocommerce' ),
					),
				),
				'fee'        => array(
					'title'       => __( 'Handling Fee', 'woocommerce' ),
					'type'        => 'text',
					'description' => __( 'Fee excluding tax, e.g. 3.50. Leave blank to disable.', 'woocommerce' ),
					'default'     => '',
				),
				'rate'       => array(
					'title'       => __( 'Shipping Rates', 'woocommerce' ),
					'type'        => 'textarea',
					'description' => __( 'Set your weight based rates in ' . get_option( 'woocommerce_weight_unit' ) . ' for country groups (one per line). Example: <code>Max weight|Cost|country group number</code>. Example: <code>10|6.95|3</code>. For decimal, use a dot not a comma.', 'woocommerce' ),
					'default'     => '',
				),
				'country_group_no' => array(
					'title' 		=> __( 'Number of country groups', 'woocommerce' ),
					'type' 			=> 'text',
					'description'	=> __( 'Number of groups of countries sharing delivery rates (hit "Save changes" button after you have changed this setting).' ),
					'default' 		=> '3',
				),

			);
		}

    /*
    * Displays country group selects in shipping method's options
    */
    function display_country_groups() {

		$woocommerce = function_exists('WC') ? WC() : $GLOBALS['woocommerce'];
		$shippingCountries = method_exists($woocommerce->countries, 'get_shipping_countries')
                                    ? $woocommerce->countries->get_shipping_countries()
                                    : $woocommerce->countries->countries;
    //   echo prp($this->settings['countries1']);
        $number = $this->country_group_no;
        for($counter = 1; $number >= $counter; $counter++) {

            $this->form_fields['countries'.$counter] =  array(
                    'title'     => sprintf(__( 'Country Group %s', 'woocommerce' ), $counter),
                    'type'      => 'multiselect',
                    'class'     => 'chosen_select',
                    'css'       => 'width: 450px;',
                    'default'   => '',
                    'options'   => $shippingCountries
            );
        }
    }

		function calculate_shipping( $package = array() ) {

			global $woocommerce;

            $rates      = $this->get_rates_by_countrygroup($this->get_countrygroup($package));
            $weight     = $woocommerce->cart->cart_contents_weight;
            $final_rate = $this->pick_smallest_rate($rates, $weight);

            if($final_rate === false) return false;

            $taxable    = ($this->tax_status == 'taxable') ? true : false;

            if($this->fee > 0 && $package['destination']['country']) $final_rate = $final_rate + $this->fee;

                $rate = array(
                'id'        => $this->id,
                'label'     => $this->title,
                'cost'      => $final_rate,
                'taxes'     => '',
                'calc_tax'  => 'per_order'
                );

        $this->add_rate( $rate );
    }

    /*
    * Retrieves the number of country group for country selected by user on checkout
    */
    function get_countrygroup($package = array()) {    

            $counter = 1;

            while(is_array($this->settings['countries'.$counter])) {
                if (in_array($package['destination']['country'], $this->settings['countries'.$counter]))
                    $country_group = $counter;

                $counter++;
            }
        return $country_group;
    }

    /*
    * Retrieves all rates available for selected country group
    */
    function get_rates_by_countrygroup($country_group = null) {

        $rates = array();
                if ( sizeof( $this->rate ) > 0) foreach ( $this->rate as $option => $value ) {

                    $rate = preg_split( '~s*|s*~', trim( $value ) );

                    if ( sizeof( $rate ) !== 3 )  {
                        continue;
                    } else {
                        $rates[] = $rate;

                    }
                }

                foreach($rates as $key) {
                    if($key[2] == $country_group) {
                        $countrygroup_rate[] = $key;
                    }
                }
        return $countrygroup_rate;
    }

    /*
    * Picks the right rate from available rates based on cart weight
    */
    function pick_smallest_rate($rates,$weight) {

    if($weight == 0) return 0; // no shipping for cart without weight

        if( sizeof($rates) > 0) foreach($rates as $key => $value) {

                if($weight <= $value[0]) {
                    $postage[] = $value[1];
                }
                $postage_all_rates[] = $value[1];
        }

        if(sizeof($postage) > 0) {
            return min($postage);
                } else {
                if (sizeof($postage_all_rates) > 0) return max($postage_all_rates);
                }
        return false;
    }

		public function admin_options() {
			?>
				<h3><?php _e( 'Weight and Country based Table Rates shipping', 'woocommerce' ); ?></h3>
				<p><?php _e( 'Lets you calculate shipping based on country and weight of the cart. Lets you set unlimited weight bands on per country basis and group countries that share same delivery cost/bands.', 'woocommerce' ); ?></p>
				<table class="form-table">
					<?php $this->generate_settings_html(); ?>
				</table>
			<?php
		}
	}
}

function add_woowctr( $methods ) {
	$methods[] = 'WCTR_Shipping';
	return $methods;
}

add_filter( 'woocommerce_shipping_methods', 'add_woowctr' );

?>

und für Express Mail

<?php
/**
 * Plugin Name: Weight and Country Table Rate Express Mail for Woocommerce
 * Description: WCTR for Express Mail is a weight and country based shipping method for Woocommerce 2.1, based on <a href="http://www.andyswebdesign.ie/blog/free-woocommerce-weight-and-country-based-shipping-extension-plugin/">AWD</a> and <a href="http://wordpress.org/plugins/weight-based-shipping-for-woocommerce/">WOOWBS</a>.
 * Version: 1.0
 * Author:
 */
/*  Copyright 2012  

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/* MODIF */ add_action( 'plugins_loaded', 'init_woowctr2', 0 );

/* MODIF */ function init_woowctr2() {

	if ( ! class_exists( 'WC_Shipping_Method' ) ) return;

/* MODIF */ 	class WCTR_Shipping2 extends WC_Shipping_Method {

		function __construct() {
/* MODIF */ 			$this->id           = 'WCTR_Shipping2';
/* MODIF */ 			$this->method_title = __( 'Table Rate for Express Mail', 'woocommerce' );

			$this->admin_page_heading     = __( 'Weight and country based shipping', 'woocommerce' );
			$this->admin_page_description = __( 'Define shipping by weight and country', 'woocommerce' );

			add_action( 'woocommerce_update_options_shipping_' . $this->id, array( &$this, 'process_admin_options' ) );

			$this->init();
			$this->display_country_groups();
		}

		function init() {
			$this->init_form_fields();
			$this->init_settings();

			$this->enabled          = $this->get_option('enabled');
			$this->title            = $this->get_option('title');
            $this->availability     = 'specific';
			$this->country_group_no	= $this->get_option('country_group_no');
            $this->countries 	    = $this->get_option('countries');
			$this->type             = 'order';
			$this->tax_status       = $this->get_option('tax_status');
			$this->fee              = $this->get_option('fee');
			$this->rate			= isset( $this->settings['rate'] ) ? $this->settings['rate'] : '';
			$this->rate			= (array) explode( "n", $this->rate );

            if (empty($this->countries)) {
                $this->availability = $this->settings['availability'] = 'all';
            }
		}

		function init_form_fields() {

            $woocommerce = function_exists('WC') ? WC() : $GLOBALS['woocommerce'];

			$this->form_fields = array(
				'enabled'    => array(
					'title'   => __( 'Enable/Disable', 'woocommerce' ),
					'type'    => 'checkbox',
					'label'   => __( 'Enable this shipping method', 'woocommerce' ),
					'default' => 'no',
				),
				'title'      => array(
					'title'       => __( 'Method Title', 'woocommerce' ),
					'type'        => 'text',
					'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
					'default'     => __( 'Express Mail', 'woocommerce' ),
				),
				'tax_status' => array(
					'title'       => __( 'Tax Status', 'woocommerce' ),
					'type'        => 'select',
					'description' => '',
					'default'     => 'taxable',
					'options'     => array(
						'taxable' => __( 'Taxable', 'woocommerce' ),
						'none'    => __( 'None', 'woocommerce' ),
					),
				),
				'fee'        => array(
					'title'       => __( 'Handling Fee', 'woocommerce' ),
					'type'        => 'text',
					'description' => __( 'Fee excluding tax, e.g. 3.50. Leave blank to disable.', 'woocommerce' ),
					'default'     => '',
				),
				'rate'       => array(
					'title'       => __( 'Shipping Rates', 'woocommerce' ),
					'type'        => 'textarea',
					'description' => __( 'Set your weight based rates in ' . get_option( 'woocommerce_weight_unit' ) . ' for country groups (one per line). Example: <code>Max weight|Cost|country group number</code>. Example: <code>10|6.95|3</code>. For decimal, use a dot not a comma.', 'woocommerce' ),
					'default'     => '',
				),
				'country_group_no' => array(
					'title' 		=> __( 'Number of country groups', 'woocommerce' ),
					'type' 			=> 'text',
					'description'	=> __( 'Number of groups of countries sharing delivery rates (hit "Save changes" button after you have changed this setting).' ),
					'default' 		=> '3',
				),

			);
		}

    /*
    * Displays country group selects in shipping method's options
    */
    function display_country_groups() {

		$woocommerce = function_exists('WC') ? WC() : $GLOBALS['woocommerce'];
		$shippingCountries = method_exists($woocommerce->countries, 'get_shipping_countries')
                                    ? $woocommerce->countries->get_shipping_countries()
                                    : $woocommerce->countries->countries;
    //   echo prp($this->settings['countries1']);
        $number = $this->country_group_no;
        for($counter = 1; $number >= $counter; $counter++) {

            $this->form_fields['countries'.$counter] =  array(
                    'title'     => sprintf(__( 'Country Group %s', 'woocommerce' ), $counter),
                    'type'      => 'multiselect',
                    'class'     => 'chosen_select',
                    'css'       => 'width: 450px;',
                    'default'   => '',
                    'options'   => $shippingCountries
            );
        }
    }

		function calculate_shipping( $package = array() ) {

			global $woocommerce;

            $rates      = $this->get_rates_by_countrygroup($this->get_countrygroup($package));
            $weight     = $woocommerce->cart->cart_contents_weight;
            $final_rate = $this->pick_smallest_rate($rates, $weight);

            if($final_rate === false) return false;

            $taxable    = ($this->tax_status == 'taxable') ? true : false;

            if($this->fee > 0 && $package['destination']['country']) $final_rate = $final_rate + $this->fee;

                $rate = array(
                'id'        => $this->id,
                'label'     => $this->title,
                'cost'      => $final_rate,
                'taxes'     => '',
                'calc_tax'  => 'per_order'
                );

        $this->add_rate( $rate );
    }

    /*
    * Retrieves the number of country group for country selected by user on checkout
    */
    function get_countrygroup($package = array()) {    

            $counter = 1;

            while(is_array($this->settings['countries'.$counter])) {
                if (in_array($package['destination']['country'], $this->settings['countries'.$counter]))
                    $country_group = $counter;

                $counter++;
            }
        return $country_group;
    }

    /*
    * Retrieves all rates available for selected country group
    */
    function get_rates_by_countrygroup($country_group = null) {

        $rates = array();
                if ( sizeof( $this->rate ) > 0) foreach ( $this->rate as $option => $value ) {

                    $rate = preg_split( '~s*|s*~', trim( $value ) );

                    if ( sizeof( $rate ) !== 3 )  {
                        continue;
                    } else {
                        $rates[] = $rate;

                    }
                }

                foreach($rates as $key) {
                    if($key[2] == $country_group) {
                        $countrygroup_rate[] = $key;
                    }
                }
        return $countrygroup_rate;
    }

    /*
    * Picks the right rate from available rates based on cart weight
    */
    function pick_smallest_rate($rates,$weight) {

    if($weight == 0) return 0; // no shipping for cart without weight

        if( sizeof($rates) > 0) foreach($rates as $key => $value) {

                if($weight <= $value[0]) {
                    $postage[] = $value[1];
                }
                $postage_all_rates[] = $value[1];
        }

        if(sizeof($postage) > 0) {
            return min($postage);
                } else {
                if (sizeof($postage_all_rates) > 0) return max($postage_all_rates);
                }
        return false;
    }

		public function admin_options() {
			?>
				<h3><?php _e( 'Weight and Country based Table Rates shipping', 'woocommerce' ); ?></h3>
				<p><?php _e( 'Lets you calculate shipping based on country and weight of the cart. Lets you set unlimited weight bands on per country basis and group countries that share same delivery cost/bands.', 'woocommerce' ); ?></p>
				<table class="form-table">
					<?php $this->generate_settings_html(); ?>
				</table>
			<?php
		}
	}
}

/* MODIF */ function add_woowctr2( $methods ) {
/* MODIF */ 	$methods[] = 'WCTR_Shipping2';
	return $methods;
}

/* MODIF */ add_filter( 'woocommerce_shipping_methods', 'add_woowctr2' );

?>

Quelle: wordpress.org

Filed Under: WordPress Tagged With: Weight Based Shipping, WooCommerce, WordPress

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • Next Page »
Anzeige

Themen

Apache Boolean values Boolesche Werte BuddyPress chmod Code Snippets Concatenation Operator Custom Post Types Datenbank Email Enfold fail2ban genesis Grid View htaccess i-mscp Indesign Layout Builder LibreOffice List View Mitgliederbereich MySQL PHP PHP Anfänger PHP Variablen Plugins Prestashop Prestashop 1.5 Prestashop 1.6 Prestashop Module Registrierung RSS Feed s2member Schreibrechte Server Shell ssl Strings Tipps Windows Windows 10 Windows 11 WooCommerce WooCommerce Sortierung WordPress
Anzeige

Letzte Kommentare

  • Martin bei CSS: Automatische Silbentrennung in einzelnen Wörtern verhindern
  • Martin bei CSS: Automatische Silbentrennung in einzelnen Wörtern verhindern
  • Klaus bei Woocommerce: Shop Seiten neu generieren
  • Thomas bei WordPress: Einzelne Kategorien aus dem RSS Feed ausschließen
  • Bernhard bei CSS: Automatische Silbentrennung in einzelnen Wörtern verhindern

Informationen

  • Kontakt
  • Datenschutzerklärung
  • Impressum
  • Cookie-Richtlinie (EU)
  • Kontakt
  • Datenschutzerklärung
  • Impressum
  • Cookie-Richtlinie (EU)
Anzeige
Cookie-Zustimmung verwalten
Um dir ein optimales Erlebnis zu bieten, verwenden wir Technologien wie Cookies, um Geräteinformationen zu speichern und/oder darauf zuzugreifen. Wenn du diesen Technologien zustimmst, können wir Daten wie das Surfverhalten oder eindeutige IDs auf dieser Website verarbeiten. Wenn du deine Zustimmung nicht erteilst oder zurückziehst, können bestimmte Merkmale und Funktionen beeinträchtigt werden.
Funktional Immer aktiv
Die technische Speicherung oder der Zugang ist unbedingt erforderlich für den rechtmäßigen Zweck, die Nutzung eines bestimmten Dienstes zu ermöglichen, der vom Teilnehmer oder Nutzer ausdrücklich gewünscht wird, oder für den alleinigen Zweck, die Übertragung einer Nachricht über ein elektronisches Kommunikationsnetz durchzuführen.
Vorlieben
Die technische Speicherung oder der Zugriff ist für den rechtmäßigen Zweck der Speicherung von Präferenzen erforderlich, die nicht vom Abonnenten oder Benutzer angefordert wurden.
Statistiken
Die technische Speicherung oder der Zugriff, der ausschließlich zu statistischen Zwecken erfolgt. Die technische Speicherung oder der Zugriff, der ausschließlich zu anonymen statistischen Zwecken verwendet wird. Ohne eine Vorladung, die freiwillige Zustimmung deines Internetdienstanbieters oder zusätzliche Aufzeichnungen von Dritten können die zu diesem Zweck gespeicherten oder abgerufenen Informationen allein in der Regel nicht dazu verwendet werden, dich zu identifizieren.
Marketing
Die technische Speicherung oder der Zugriff ist erforderlich, um Nutzerprofile zu erstellen, um Werbung zu versenden oder um den Nutzer auf einer Website oder über mehrere Websites hinweg zu ähnlichen Marketingzwecken zu verfolgen.
Optionen verwalten Dienste verwalten Anbieter verwalten Lese mehr über diese Zwecke
Einstellungen ansehen
{title} {title} {title}