Pagina 76 van 76

Re: Webdevelopment topic

Geplaatst: dinsdag 27 september 2016, 1:22
door Armajail
Even hulp nodig van mensen die goed zijn in php...

Ik ben met WooCommerce bezig om een optie bij ieder product een checkbox te plaatsen " [X] In geschenkmand plaatsen van 5 euro? ".
Ik heb hiervoor een plugin gevonden, die helaas al 2 jaar niet meer vernieuwd werd.

Prachtige plugin though, maar het probleem is:
Als ik bv. 2 producten in dezelfde geschenkmand wil plaatsen, rekent dit 2x de 5euro aan, dat is natuurlijk niet de bedoeling.
De bedoeling is dat er slechts 1x 5 euro wordt aangerekend, onafhankelijk hoeveel producten er aangevinkt voor de geschenkmand.

Lijkt me dat je maar ergens 1 lijn moet veranderen, weet alleen niet welke juist... en hoe.

Ik heb de code hieronder:
In- of uitklappen •

Code: Selecteer alles

<?php
/*
Plugin Name: WooCommerce Product Gift Wrap
Plugin URI: https://github.com/mikejolley/woocommerce-product-gift-wrap
Description: Add an option to your products to enable gift wrapping. Optionally charge a fee.
Version: 1.1.0
Author: Mike Jolley
Author URI: http://mikejolley.com
Requires at least: 3.5
Tested up to: 4.0
Text Domain: woocommerce-product-gift-wrap
Domain Path: /languages/

	Copyright: © 2014 Mike Jolley.
	License: GNU General Public License v3.0
	License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/

/**
 * Localisation
 */
load_plugin_textdomain( 'woocommerce-product-gift-wrap', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );

/**
 * WC_Product_Gift_wrap class.
 */
class WC_Product_Gift_Wrap {

	/**
	 * Hook us in :)
	 *
	 * @access public
	 * @return void
	 */
	public function __construct() {
		$default_message                 = '{checkbox} '. sprintf( __( 'Gift wrap this item for %s?', 'woocommerce-product-gift-wrap' ), '{price}' );
		$this->gift_wrap_enabled         = get_option( 'product_gift_wrap_enabled' ) == 'yes' ? true : false;
		$this->gift_wrap_cost            = get_option( 'product_gift_wrap_cost', 0 );
		$this->product_gift_wrap_message = get_option( 'product_gift_wrap_message' );

		if ( ! $this->product_gift_wrap_message ) {
			$this->product_gift_wrap_message = $default_message;
		}

		add_option( 'product_gift_wrap_enabled', 'no' );
		add_option( 'product_gift_wrap_cost', '0' );
		add_option( 'product_gift_wrap_message', $default_message );

		// Init settings
		$this->settings = array(
			array(
				'name' 		=> __( 'Gift Wrapping Enabled by Default?', 'woocommerce-product-gift-wrap' ),
				'desc' 		=> __( 'Enable this to allow gift wrapping for products by default.', 'woocommerce-product-gift-wrap' ),
				'id' 		=> 'product_gift_wrap_enabled',
				'type' 		=> 'checkbox',
			),
			array(
				'name' 		=> __( 'Default Gift Wrap Cost', 'woocommerce-product-gift-wrap' ),
				'desc' 		=> __( 'The cost of gift wrap unless overridden per-product.', 'woocommerce-product-gift-wrap' ),
				'id' 		=> 'product_gift_wrap_cost',
				'type' 		=> 'text',
				'desc_tip'  => true
			),
			array(
				'name' 		=> __( 'Gift Wrap Message', 'woocommerce-product-gift-wrap' ),
				'id' 		=> 'product_gift_wrap_message',
				'desc' 		=> __( 'Note: <code>{checkbox}</code> will be replaced with a checkbox and <code>{price}</code> will be replaced with the gift wrap cost.', 'woocommerce-product-gift-wrap' ),
				'type' 		=> 'text',
				'desc_tip'  => __( 'The checkbox and label shown to the user on the frontend.', 'woocommerce-product-gift-wrap' )
			),
		);

		// Display on the front end
		add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'gift_option_html' ), 10 );

		// Filters for cart actions
		add_filter( 'woocommerce_add_cart_item_data', array( $this, 'add_cart_item_data' ), 10, 2 );
		add_filter( 'woocommerce_get_cart_item_from_session', array( $this, 'get_cart_item_from_session' ), 10, 2 );
		add_filter( 'woocommerce_get_item_data', array( $this, 'get_item_data' ), 10, 2 );
		add_filter( 'woocommerce_add_cart_item', array( $this, 'add_cart_item' ), 10, 1 );
		add_action( 'woocommerce_add_order_item_meta', array( $this, 'add_order_item_meta' ), 10, 2 );

		// Write Panels
		add_action( 'woocommerce_product_options_pricing', array( $this, 'write_panel' ) );
		add_action( 'woocommerce_process_product_meta', array( $this, 'write_panel_save' ) );

		// Admin
		add_action( 'woocommerce_settings_general_options_end', array( $this, 'admin_settings' ) );
		add_action( 'woocommerce_update_options_general', array( $this, 'save_admin_settings' ) );
	}

	/**
	 * Show the Gift Checkbox on the frontend
	 *
	 * @access public
	 * @return void
	 */
	public function gift_option_html() {
		global $post;

		$is_wrappable = get_post_meta( $post->ID, '_is_gift_wrappable', true );

		if ( $is_wrappable == '' && $this->gift_wrap_enabled ) {
			$is_wrappable = 'yes';
		}

		if ( $is_wrappable == 'yes' ) {

			$current_value = ! empty( $_REQUEST['gift_wrap'] ) ? 1 : 0;

			$cost = get_post_meta( $post->ID, '_gift_wrap_cost', true );

			if ( $cost == '' ) {
				$cost = $this->gift_wrap_cost;
			}

			$price_text = $cost > 0 ? woocommerce_price( $cost ) : __( 'free', 'woocommerce-product-gift-wrap' );
			$checkbox   = '<input type="checkbox" name="gift_wrap" value="yes" ' . checked( $current_value, 1, false ) . ' />';

			woocommerce_get_template( 'gift-wrap.php', array(
				'product_gift_wrap_message' => $this->product_gift_wrap_message,
				'checkbox'                  => $checkbox,
				'price_text'                => $price_text
			), 'woocommerce-product-gift-wrap', untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' );
		}
	}

	/**
	 * When added to cart, save any gift data
	 *
	 * @access public
	 * @param mixed $cart_item_meta
	 * @param mixed $product_id
	 * @return void
	 */
	public function add_cart_item_data( $cart_item_meta, $product_id ) {
		$is_wrappable = get_post_meta( $product_id, '_is_gift_wrappable', true );

		if ( $is_wrappable == '' && $this->gift_wrap_enabled ) {
			$is_wrappable = 'yes';
		}

		if ( ! empty( $_POST['gift_wrap'] ) && $is_wrappable == 'yes' ) {
			$cart_item_meta['gift_wrap'] = true;
		}

		return $cart_item_meta;
	}

	/**
	 * Get the gift data from the session on page load
	 *
	 * @access public
	 * @param mixed $cart_item
	 * @param mixed $values
	 * @return void
	 */
	public function get_cart_item_from_session( $cart_item, $values ) {

		if ( ! empty( $values['gift_wrap'] ) ) {
			$cart_item['gift_wrap'] = true;

			$cost = get_post_meta( $cart_item['data']->id, '_gift_wrap_cost', true );

			if ( $cost == '' ) {
				$cost = $this->gift_wrap_cost;
			}

			$cart_item['data']->adjust_price( $cost );
		}

		return $cart_item;
	}

	/**
	 * Display gift data if present in the cart
	 *
	 * @access public
	 * @param mixed $other_data
	 * @param mixed $cart_item
	 * @return void
	 */
	public function get_item_data( $item_data, $cart_item ) {
		if ( ! empty( $cart_item['gift_wrap'] ) )
			$item_data[] = array(
				'name'    => __( 'In geschenkmand', 'woocommerce-product-gift-wrap' ),
				'value'   => __( 'Yes', 'woocommerce-product-gift-wrap' ),
				'display' => __( 'Ja', 'woocommerce-product-gift-wrap' )
			);

		return $item_data;
	}

	/**
	 * Adjust price after adding to cart
	 *
	 * @access public
	 * @param mixed $cart_item
	 * @return void
	 */
	public function add_cart_item( $cart_item ) {
		if ( ! empty( $cart_item['gift_wrap'] ) ) {

			$cost = get_post_meta( $cart_item['data']->id, '_gift_wrap_cost', true );

			if ( $cost == '' ) {
				$cost = $this->gift_wrap_cost;
			}

			$cart_item['data']->adjust_price( $cost );
		}

		return $cart_item;
	}

	/**
	 * After ordering, add the data to the order line items.
	 *
	 * @access public
	 * @param mixed $item_id
	 * @param mixed $values
	 * @return void
	 */
	public function add_order_item_meta( $item_id, $cart_item ) {
		if ( ! empty( $cart_item['gift_wrap'] ) ) {
			woocommerce_add_order_item_meta( $item_id, __( 'In geschenkmand', 'woocommerce-product-gift-wrap' ), __( 'Ja', 'woocommerce-product-gift-wrap' ) );
		}
	}

	/**
	 * write_panel function.
	 *
	 * @access public
	 * @return void
	 */
	public function write_panel() {
		global $post;

		echo '</div><div class="options_group show_if_simple show_if_variable">';

		$is_wrappable = get_post_meta( $post->ID, '_is_gift_wrappable', true );

		if ( $is_wrappable == '' && $this->gift_wrap_enabled ) {
			$is_wrappable = 'yes';
		}

		woocommerce_wp_checkbox( array(
				'id'            => '_is_gift_wrappable',
				'wrapper_class' => '',
				'value'         => $is_wrappable,
				'label'         => __( 'Gift Wrappable', 'woocommerce-product-gift-wrap' ),
				'description'   => __( 'Enable this option if the customer can choose gift wrapping.', 'woocommerce-product-gift-wrap' ),
			) );

		woocommerce_wp_text_input( array(
				'id'          => '_gift_wrap_cost',
				'label'       => __( 'Gift Wrap Cost', 'woocommerce-product-gift-wrap' ),
				'placeholder' => $this->gift_wrap_cost,
				'desc_tip'    => true,
				'description' => __( 'Override the default cost by inputting a cost here.', 'woocommerce-product-gift-wrap' ),
			) );

		wc_enqueue_js( "
			jQuery('input#_is_gift_wrappable').change(function(){

				jQuery('._gift_wrap_cost_field').hide();

				if ( jQuery('#_is_gift_wrappable').is(':checked') ) {
					jQuery('._gift_wrap_cost_field').show();
				}

			}).change();
		" );
	}

	/**
	 * write_panel_save function.
	 *
	 * @access public
	 * @param mixed $post_id
	 * @return void
	 */
	public function write_panel_save( $post_id ) {
		$_is_gift_wrappable = ! empty( $_POST['_is_gift_wrappable'] ) ? 'yes' : 'no';
		$_gift_wrap_cost   = ! empty( $_POST['_gift_wrap_cost'] ) ? woocommerce_clean( $_POST['_gift_wrap_cost'] ) : '';

		update_post_meta( $post_id, '_is_gift_wrappable', $_is_gift_wrappable );
		update_post_meta( $post_id, '_gift_wrap_cost', $_gift_wrap_cost );
	}

	/**
	 * admin_settings function.
	 *
	 * @access public
	 * @return void
	 */
	public function admin_settings() {
		woocommerce_admin_fields( $this->settings );
	}

	/**
	 * save_admin_settings function.
	 *
	 * @access public
	 * @return void
	 */
	public function save_admin_settings() {
		woocommerce_update_options( $this->settings );
	}
}

new WC_Product_Gift_Wrap();



Re: Webdevelopment topic

Geplaatst: maandag 3 oktober 2016, 13:28
door Armajail
Niemand een antwoord?

Re: Webdevelopment topic

Geplaatst: zondag 23 oktober 2016, 14:55
door Ruthless
Ik begrijp niet helemaal wat je probeert te doen, sorry

Re: Webdevelopment topic

Geplaatst: zondag 23 oktober 2016, 19:54
door Bighead
Ik ga deze clusterfuck niet tot dusverre doorlezen dat ik er wat van begrijp, maar ergens worden de totale kosten aan een variabele toegewezen. Als je die op dat punt gewoon overschrijft met wat je wil dat het kost ga je dat hele probleem uit de weg.

Re: Webdevelopment topic

Geplaatst: maandag 14 november 2016, 15:38
door Armajail
Verkopen jullie eigenlijk ook themes en andere dingen online? (Bv op ThemeForest)

Re: Webdevelopment topic

Geplaatst: zondag 19 februari 2017, 20:39
door Kev
Dus nog mensen die coderen? Topic is zo dood.

Re: Webdevelopment topic

Geplaatst: maandag 20 februari 2017, 12:46
door Rallim
Jaja, hard bezig in asp.net

Re: Webdevelopment topic

Geplaatst: dinsdag 21 februari 2017, 20:28
door Wesley
Druk bezig op stage met Meteor, React, Docker en in mijn vrije tijd bezig met Webpack, Redux, Express, React, Docker, PostCSS etc etc. Super tof allemaal :D

Re: Webdevelopment topic

Geplaatst: donderdag 16 maart 2017, 19:51
door Rallim
Zoals ik hiervoor al postte ben ik bezig met ASP.Net, specifiek MVC5. We zitten nu alleen even te ruziën of we Autofac of Unity gaan gebruiken voor (vooral) dependency injection. Ik zit te googelen naar comparisons etc maar het meeste wat ik tegenkom is al enigszins gedateerd. Iemand hier die zijn ervaringen kan delen?

(Hoe lief het ook bedoeld is, maar je hoeft niet voor me te googelen. Ik zoek puur mensen met zelf ervaring ;))

Re: Webdevelopment topic

Geplaatst: donderdag 6 april 2017, 20:15
door Kev
Ik begin morgen met een cursus Objective C :D

Re: Webdevelopment topic

Geplaatst: vrijdag 16 juni 2017, 15:36
door Armajail
Zag eens dat iemand vroeg voor een 'responsible' website, ipv 'responsive' .. lol

Re: Webdevelopment topic

Geplaatst: zondag 18 juni 2017, 20:30
door Kev
:'D

Re: Webdevelopment topic

Geplaatst: zondag 9 juli 2017, 20:24
door Armajail
Om de een of andere reden krijg ik geen enkele (buiten een, maar die gaat niet weg nadat je op OK klikt) cookie werkend op m'n WP-website.
't Is een HTML5blank gebaseerde website.

Ik heb 't al op 2 fora (WP en StackOverflow gevraagd, maar zonder resultaat.

Is er iets waar ik op moet letten, wat zou kunnen weerhouden dat de cookies niet verschijnen? Iets ivm de footer.php, of functions.php ofzo?

Ty!

Re: Webdevelopment topic

Geplaatst: dinsdag 11 juli 2017, 19:12
door Kev

Re: Webdevelopment topic

Geplaatst: zaterdag 14 juli 2018, 11:11
door Armajail
Ik moet een website maken met Joomla (wat heb ik een hekel aan Joomla!)

maar ik moet iets als dit maken:
Afbeelding

Dus, de webpagina is een "artikel", daarin heb ik een module ''articles - categorised" geloof ik,
en bij Artikels heb ik een categorie, genaamd "Artikelen", waar nieuwe Artikels zouden moeten verschijnen, die ik onder deze categorie plaats.
Ook moeten er variaties zijn, de id's moeten uniek zijn, zodat ik sommigen een gele kleur kan geven, andere rood.

Is dit mogelijk, en hoe doe ik dat? Ty!

Re: Webdevelopment topic

Geplaatst: zaterdag 14 juli 2018, 16:47
door Ruthless
jooma deinstalleren

Re: Webdevelopment topic

Geplaatst: woensdag 18 juli 2018, 13:30
door Niels
idk wtf joomla is maar in de tijd van die paint tekening had je ook ff een youtube tutorial kunnen kijken

waarom heb je zelf ook nog niks geprobeerd? doe dat, en kom dan terug

Re: Webdevelopment topic

Geplaatst: zondag 5 augustus 2018, 15:28
door Armajail
Thx tho, uiteraard heb ik ondertussen zelf vanalles geprbeerd, en het is uiteindelijk gelukt. Joomla is een andere tool zoals WordPress.

Re: Webdevelopment topic

Geplaatst: zondag 5 augustus 2018, 16:16
door Ruthless
eentje waar al jaren geleden is uitgeroepen tot meest onveilige cms en ze nooit hun datalekken goed gefixt hebben

Re: Webdevelopment topic

Geplaatst: donderdag 9 augustus 2018, 17:49
door Armajail
Eindelijk, de persoon in kwestie heeft tòch gekozen voor WP