Wir kennen es alle, Kunden haben Geburtstag, es gibt die verschiedensten Feiertage oder die Sommer Monate und hier will man Rabattaktionen starten. Dazu müsste man jedoch immer Rabattcodes anlegen. Wieso nicht automatisch? Dieses Skriptbeispiel hier regelt Feiertage und Co. automatisch. Als Beispiel wurde hier Weihnachten eingetragen. Es kann ganz simpel auch für Geburtstage, Black Friday, Cyber Monday, Ostern und Co genutzt werden. Jeder Kunde bekommt dazu einen eigenen Rabattcode, man könnte dies auch ändern, dass jeder Kunde den selben nutzen kann.
Das ganze wurde zwar auf teklab.de genutzt, jedoch für das Beispiel hier umgeschrieben, daher ungetestet es kann also noch ein Schreibfehler drinstecken
Erstellt eine /mytekbase/members/widgets/mega_autocode.php mit dem Inhalt:
<?php
$day = strftime("%d", time());
$month = strftime("%m", time());
$year = strftime("%Y", time());
$discountcode = "";
$discountall = 0;
$startdate = time();
$db->sql_query("DELETE FROM ".$prefix."_shop_codes WHERE enddate<'$startdate'");
if ($day > 1 AND $day < 25 AND $month == 12) {
$discount = 10; //Prozent
$discountcode = "XMAS"; //Kennung
$discountall = 1; // Für alle Kunden 1=Ja / 0=Nein
$discounttxt = "Beispieltext für einen Rabattcode mit ".$discount."% welcher bis zum %discountdate% gültig ist. Der Rabattcode %discountkey%.";
$enddate = strtotime("2017-12-25"); // Gültig bis
}
// weitere Aktionen z.B. zum Geburtstag = memstats[birthday]
if ("$day.$month.$year" == $memstats[birthday]) {
$discount = 20; //Prozent
$discountcode = "BDAY";
$enddate = $startdate + 604800; // 7 Tage gültig
$discounttxt = "Beispieltext für einen Rabattcode mit ".$discount."% welcher bis zum %discountdate% gültig ist. Der Rabattcode %discountkey%.";
}
if ($discountcode != "") {
$chkconvertdate = ''._CONVERTDATE.'';
$chkconvertdate = str_replace("dd","%d",$chkconvertdate);
$chkconvertdate = str_replace("mm","%m",$chkconvertdate);
$chkconvertdate = str_replace("yy","%Y",$chkconvertdate);
if ($discountall == 1) {
$discountstats = $db->sql_fetchrow($db->sql_query("SELECT * FROM ".$prefix."_shop_codes WHERE code LIKE '%$discountcode%' ORDER BY id DESC LIMIT 1"));
$randnum = rand(1000,9999);
$discountkey = "$discountcode-$randnum";
}else{
$discountstats = $db->sql_fetchrow($db->sql_query("SELECT * FROM ".$prefix."_shop_codes WHERE code LIKE '%$memstats[member]-$discountcode%' ORDER BY id DESC LIMIT 1"));
$discountkey = "$memstats[member]-$discountcode";
}
if (!$discountstats) {
$discountdate = strftime("$chkconvertdate, %H:%M", $enddate);
$result = $db->sql_query("INSERT INTO ".$prefix."_shop_codes (id, code, monper, startdate, enddate, count, status, taxid) VALUES (NULL, '$discountkey', '$discount', '$startdate', '$enddate', '10', '1', '2')");
}else{
$discountdate = strftime("$chkconvertdate, %H:%M", $discountstats[enddate]);
$discountkey = "$discountstats[code]";
}
if (!$discountstats OR $discountstats[enddate] > $startdate) {
$discounttxt = str_replace("%discountdate%", $discountdate, $discounttxt);
$discounttxt = str_replace("%discountkey%", $discountkey, $discounttxt);
$membermsg = member_msg($discounttxt);
echo '<div class="box-wrapper"><div class="row"><div class="col-md-12">'.$membermsg.'</div></div></div>';
}
}
?>
Alles anzeigen
Fertig