我正在一家基于Woocommerce的餐馆网站上工作 - 客户对他的产品有不同的价格 - 一个交货价格和一个坐着的价格。
客户可以订购产品并交付,也可以通过订购产品在餐厅预订餐桌,在结账部分他可以选择书籍选项。
那么 - 我能为产品定价2,然后根据交货方式应用其中一种产品吗?
变化并不是一个好主意 - 因为我不能在购物车中有一个用于坐着的产品和一个用于预订的产品。
答案 0 :(得分:0)
检查以下代码,它可能会让您了解满足您的要求。
void *thread_handle_connection(void *arg) {
char buffer[MAX_MSG_SIZE]; // Receive buffer
int bytes_read;
do {
// If there aren't any connections, sleep and recheck every second
while(!num_connections && !term_requested) {
sleep(1);
}
// Lock out connections queue and grab the first one
pthread_mutex_lock(&queue_mutex);
int connectionfd = remove_connection_from_queue();
pthread_mutex_unlock(&queue_mutex);
if(-1 == connectionfd) {
continue;
}
// pthread_barrier_wait(&barrier); // Barrier for threads - for testing only
// Read up to 1024 bytes from the client
bytes_read = recv(connectionfd, buffer, MAX_MSG_SIZE - 1, 0);
// If the data was read successfully
if(bytes_read > 0) {
// Add a terminating NULL character and print the message received
buffer[bytes_read] = '\0';
// Calculate response
int multiplicand = atoi(buffer);
char *response;
asprintf(&response, "%d", multiplicand * MULTIPLIER);
// Echo the data back to the client; exit loop if we're unable to send
if(-1 == send(connectionfd, response, strlen(response), 0)) {
warn("Unable to send data to client");
break;
}
free(response);
}
// Close connection
close(connectionfd);
} while(bytes_read > 0 && !term_requested);
return NULL;
}