如何在结帐页面中创建新的部分 - woocommerce

时间:2017-04-10 09:31:23

标签: wordpress woocommerce

在woocommerce的结帐页面, 我想创建新的(块或部分),我不知道如何调用OK。

如现场演示: http://tigon.freshbrand.vn/checkout/

或img描述我的问题:http://prntscr.com/eum61d

我想创建更多这样的部分。

MY SECTION FORM 1 TITLE.
 - input 1
 - input 2

MY SECTION FORM 2 TITLE
 - input 3
 - input 4

MY SECTION FORM 3 TITLE
 - input 5
 - input 6

如何解决这个问题, 帮助我。

1 个答案:

答案 0 :(得分:2)

尝试使用以下代码在结帐页面中添加部分。我在本节中仅为您添加了内容。您也可以添加字段。

import re
import codecs
import csv
import nltk
import sklearn
from sklearn import cross_validation
import pandas as pd


# variaveis
tweets = []
caracteristicas = []
testBase = []
testset = []

# Tweet pre-processing
def preProcessamentoText(tweet):
    # converte para minusculas
    tweet = tweet.lower()

    # remove URLs (www.* ou https?://*)
    tweet = re.sub('((www\.[^\s]+)|(https?://[^\s]+))','URL',tweet)

    # remove @username
    tweet = re.sub('@[^\s]+','AT_USER',tweet)

    # remove multiplos espacos em brancos
    tweet = re.sub('[\s]+', ' ', tweet)

    # substitui #work por work
    tweet = re.sub(r'#([^\s]+)', r'\1', tweet)

    # trim
    tweet = tweet.strip('\'"')

    return tweet
#end

# list of stopWords
def getStopWords(stopWordListFileName):

    stopWords = []
    stopWords = nltk.corpus.stopwords.words('portuguese')
    stopWords.append('AT_USER')
    stopWords.append('URL')

    fp = codecs.open(stopWordListFileName, encoding='utf-8')
    line = fp.readline()
    while line:
        word = line.strip()
        stopWords.append(word)
        line = fp.readline()
    fp.close()

    return stopWords
#end

# Remove repeat letters. Ex.: leeeeento = lento
def removeRepeticao(s):
    pattern = re.compile(r"(.)\1{1,}", re.DOTALL)
    return pattern.sub(r"\1\1", s)
#end

# Feature vector
def getVetorCaracteristicas(tweet):

    featureVector = []
    stopWords = getStopWords('data/stopwords_pt-BR.txt')
    words = tweet.split()
    for w in words:

        # remove letras repetidas
        w = removeRepeticao(w)

        # remove sinais de pontuacao
        w = w.strip('\'"?,.')

        # verifica se a palavra inicia com numero
        val = re.search(r"^[a-zA-Z][a-zA-Z0-9]*$", w)

        # não adiciona se a palavra já existe na lista
        # ou se a palavra começa com número
        # ou tem tamanha menos que 2
        if(w in stopWords or val is None or len(w) <= 2):
            continue
        else:
            featureVector.append(w.lower())

    return featureVector
#end

#load trainset
def carregarTextos():

    global caracteristicas

    inpTexts = csv.reader(open('data/baseTreino.csv', 'rb'), delimiter=',', quotechar='|')
    for row in inpTexts:
        #print row
        sentimento = row[0]
        tweet = row[1]
        textoProcessado = preProcessamentoText(tweet)
        vetorCaracteristicas = getVetorCaracteristicas(textoProcessado)
        caracteristicas.extend(vetorCaracteristicas)
        tweets.append((vetorCaracteristicas,sentimento))
        #print tweets
    #end loop

    # remove entradas duplicadas
    caracteristicas = list(set(caracteristicas))

#load testSet
def test_set():
    global testBase

    #Lendo o conjunto de testes
    testTexts = csv.reader(open('data/baseTestes.csv', 'rb'), delimiter=',', quotechar='|')
    for row in testTexts:
        #print row
        sentimento = row[0]
        tweet = row[1]
        textoProcessado = preProcessamentoText(tweet)
        vetorCaracteristicas = getVetorCaracteristicas(textoProcessado)
        testBase.extend(vetorCaracteristicas)
        testset.append((vetorCaracteristicas,sentimento))
        #print testset

    testBase = list(set(testBase))

#Extraction of characteristics
def extracaoCaracteristicas(tweet):

    #print tweet

    palavras = set(tweet)
    lista = {}
    for palavra in caracteristicas:
        lista['contains(%s)' % palavra] = (palavra in palavras)
    #end loop
    return lista

#Method to classify the text according to the feeling
def classificaTexto(tweet):

    textoProcessado = preProcessamentoText(tweet)
    result = NBClassifier.classify(extracaoCaracteristicas(getVetorCaracteristicas(textoProcessado)))

    #print result
    if (result == 4) :
        print 'Crime não categorizado - ' + tweet
    elif (result == 1):
        print 'Roubo - ' + tweet
    elif(result == 2):
        print 'Homicídio - ' + tweet
    elif(result== 3):
        print 'Tráfico - ' + tweet
    else :
        print 'Não representa um crime - ' + tweet


# Main function
if __name__ == '__main__':
    #load the 2 set (train and test)
    carregarTextos()
    test_set()

    # Extract the feature vector of all tweets in one go
    conjuntoTreino = nltk.classify.util.apply_features(extracaoCaracteristicas, tweets)
    conjuntoTeste = nltk.classify.util.apply_features(extracaoCaracteristicas,testset)

    # Train the classifier
    #NBClassifier = nltk.NaiveBayesClassifier.train(conjuntoTreino)
    #print 'accuracy:', (nltk.classify.util.accuracy(NBClassifier, conjuntoTeste))

    #CrossValidation - Using ScikitLearn and NLTK
    cv = cross_validation.KFold(len(conjuntoTreino), n_folds=10, shuffle=False, random_state=None)
    for traincv, testcv in cv:
        classifier = nltk.NaiveBayesClassifier.train(conjuntoTreino[traincv[0]:traincv[len(traincv)-1]])
        print 'accuracy:', nltk.classify.util.accuracy(classifier, conjuntoTreino[testcv[0]:testcv[len(testcv)-1]])

使用JS来切换部分。