wordpress 相关问题

此标记用于有关WordPress内容管理系统的特定于编程的问题。非主题问题包括主题开发,WordPress管理,管理最佳实践,服务器配置等。最好在Stack Exchange WordPress开发中提出这些问题。

如何使用 WP REST API 发出订单请求以利用 WooCommerce 彩票插件进行门票分配?

我正在开发一个抽奖彩票 WordPress 网站(网站链接),该网站在 WooCommerce 彩票和 WooCommerce 彩票选号插件上运行。我正在尝试外部订票或购买...

回答 1 投票 0

wordpress 网页上的 401 并显示全白

我有一个 WordPress 网站,直到今天早上都运行良好。现在,所有页面都显示白色。 有趣的是,如果我将鼠标悬停在白页上,我可以看到背面的链接。 什...

回答 1 投票 0

如何导入更新的 WordPress 产品描述?

我有一个包含 500 行和两列的 CSV 文件:产品 ID 和描述。我该如何使用 SQL 更新 Wordpress 中的描述?我对 SQL 很熟悉,但不知道是什么领域......

回答 1 投票 0

如何通过 REST API 修复对 WordPress 网站的订单请求?

<?php function createOrder($selectedGame_id, $quantityToBuy, $totalPrice, $msisdn) { $consumer_key = ''; //intentionally removed $consumer_secret = ''; //intentionally removed $order_url = 'https://www.afrolottogh.com/wp-json/wc/v3/orders'; $auth = base64_encode($consumer_key . ":" . $consumer_secret); $customerExists = checkAndCreateCustomer($msisdn); //function that checks for the existence of a customer based on the phone number that dialled the USSD code. $customer_data = $customerExists ? $customerExists : null; //if customer exists then the details of the customer would be used to make the order if ($customerExists) { $order_data = array( 'payment_method' => 'bacs', 'payment_method_title' => 'Afro Lotto Checkout', 'set_paid' => true, 'billing' => array( 'first_name' => $customer_data['first_name'], 'last_name' => $customer_data['last_name'], 'address_1' => $customer_data['billing']['address_1'], 'address_2' => $customer_data['billing']['address_2'], 'city' => $customer_data['billing']['city'], 'state' => $customer_data['billing']['state'], 'postcode' => $customer_data['billing']['postcode'], 'country' => $customer_data['billing']['country'], 'email' => $customer_data['email'], 'phone' => $customer_data['billing']['phone'] ), 'shipping' => array( 'first_name' => $customer_data['shipping']['first_name'], 'last_name' => $customer_data['shipping']['last_name'], 'address_1' => $customer_data['shipping']['address_1'], 'address_2' => $customer_data['shipping']['address_2'], 'city' => $customer_data['shipping']['city'], 'state' => $customer_data['shipping']['state'], 'postcode' => $customer_data['shipping']['postcode'], 'country' => $customer_data['shipping']['country'] ), 'line_items' => array( array( 'product_id' => $selectedGame_id, 'quantity' => $quantityToBuy ) ), 'shipping_lines' => array( array( 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => $totalPrice ) ) ); } else { $order_data = array( 'payment_method' => 'bacs', 'payment_method_title' => 'Afro Lotto Checkout', 'set_paid' => true, 'billing' => array( 'first_name' => $msisdn, 'last_name' => 'USSD', 'address_1' => 'USSD', 'address_2' => '', 'city' => 'USSD', 'state' => 'AH', 'postcode' => '', 'country' => 'GH', 'email' => $msisdn . '@gmail.com', 'phone' => $msisdn ), 'shipping' => array( 'first_name' => $msisdn, 'last_name' => 'USSD', 'address_1' => 'USSD', 'address_2' => '', 'city' => 'USSD', 'state' => 'AH', 'postcode' => '', 'country' => 'GH' ), 'line_items' => array( array( 'product_id' => $selectedGame_id, 'quantity' => $quantityToBuy ) ), 'shipping_lines' => array( array( 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => $totalPrice ) ) ); } // Send request to create order $ch = curl_init($order_url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($order_data)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic ' . $auth)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // Process response $order_response = json_decode($response, true); // Check if order creation was successful if (isset($order_response['id'])) { return "Order created successfully. Order ID: " . $order_response['id']; } else { return "Failed to create order. Error: " . $order_response['message']; } } ?> 我上面的代码没有按预期创建订单,我正在通过 USSD 系统使用 REST API 向 WordPress 网站发出订单请求。 因此,我使用 Postman 来测试与网站的 API 连接,方法是使用默认 API 端点购买实时产品来创建订单,并且它有效 我的挑战是如何让 PHP 文件能够做到这一点因为 PHP 代码中已经提供了所需的每个参数,但 WordPress 网站上没有显示任何订单 { "payment_method": "bacs", "payment_method_title": "Afro Lotto Checkout", "set_paid": true, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "123 Main St", "city": "Anytown", "state": "CA", "postcode": "12345", "country": "US", "email": "[email protected]", "phone": "123456789" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "123 Main St", "city": "Anytown", "state": "CA", "postcode": "12345", "country": "US" }, "line_items": [ { "product_id": 41660, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "5.00" } ] } 这是 $response 变量的值: Order creation response: { "code":"rest_invalid_param", "message":"Invalid parameter(s): billing, shipping, shipping_lines", "data":{ "status":400, "params":{ "billing":"billing[first_name] is not of type string.", "shipping":"shipping[first_name] is not of type string.", "shipping_lines":"shipping_lines[0][total] is not of type string." }, "details":{ "billing":{ "code":"rest_invalid_type", "message":"billing[first_name] is not of type string.", "data":{ "param":"billing[first_name]" } }, "shipping":{ "code":"rest_invalid_type", "message":"shipping[first_name] is not of type string.", "data":{ "param":"shipping[first_name]" } }, "shipping_lines":{ "code":"rest_invalid_type", "message":"shipping_lines[0][total] is not of type string.", "data":{ "param":"shipping_lines[0][total]" } } } } } 邮递员测试结果图片 所以我根据错误日志的响应对代码做了一些更改。我定义了计费和运输的默认值: // Define default billing and shipping values $default_billing_values = array( 'first_name' => (string)$msisdn, 'last_name' => 'USSD', 'address_1' => 'USSD', 'address_2' => '', 'city' => 'USSD', 'state' => 'AH', 'postcode' => '', 'country' => 'GH', 'email' => '[email protected]', 'phone' => (string)$msisdn ); $default_shipping_values = array( 'first_name' => (string)$msisdn, 'last_name' => 'USSD', 'address_1' => 'USSD', 'address_2' => '', 'city' => 'USSD', 'state' => 'AH', 'postcode' => '', 'country' => 'GH' ); 然后我使用客户的信息(如果存在),否则我使用默认值: // Check if customer exists, use customer data if available, otherwise use default values if ($customerExists) { $customer_id = isset($customer_data['id']) ? $customer_data['id'] : null; $billing_data = isset($customer_data['billing']) ? $customer_data['billing'] : $default_billing_values; $shipping_data = isset($customer_data['shipping']) ? $customer_data['shipping'] : $default_shipping_values; } else { $billing_data = $default_billing_values; $shipping_data = $default_shipping_values; } 然后我构建订单数据: // Construct order data $order_data = array( 'payment_method' => 'paystack', 'payment_method_title' => 'paystack', 'customer_id' => intval($customer_id), 'set_paid' => true, 'billing' => $billing_data, 'shipping' => $shipping_data, 'line_items' => array( array( 'product_id' => intval($product_id), 'quantity' => intval($quantity) ) ), 'shipping_lines' => array( array( 'method_id' => 'free_shipping', 'method_title' => 'Free Shipping', 'total' => '0.00' ) ) ); 其余代码基本保持不变:) 祝你好运,编码愉快!

回答 1 投票 0

仅在 WooCommerce 中显示特定地理位置国家/地区的产品价格

我已经使用 WooCommerce 开发了一个目录,但是由于我无法控制的原因,我需要能够向从英国境外访问该网站的用户隐藏产品价格。 我找到了 p...

回答 2 投票 0

定义的产品自定义字段值替换 WooCommerce 循环上的价格[已关闭]

在我的 WooCommerce 产品上,我想用产品型号参考自定义字段(例如:#AB2568B)替换产品价格。如何显示型号参考而不是价格?请帮忙。

回答 1 投票 0

WooCommerce 中的自定义条件购物车商品价格

我遇到了一个问题,几周来我一直在努力解决这个问题。尝试了我在互联网上可以找到的所有内容。 简而言之,它是一个订购助手的系统(用于清洁),我使用

回答 1 投票 0

使用 WooCommerce get_price 显示带有千位分隔符的四舍五入产品自定义价格

通过 woocommerce,我试图获得带有千位分隔符和货币的自定义舍入产品价格: 这是我的代码:

回答 1 投票 0

WooCommerce 测量价格计算 - 用最低价格替换价格范围

希望标题是不言自明的!我在这里使用 WooCommerce 中的测量价格计算器 (MPC)。我在我的functions.php中添加了调整来改变变量上的价格显示

回答 1 投票 0

根据 Woocommerce 中用户相关的购买动态更改产品价格[已关闭]

当我添加此 $product->get_id() 时,我收到 HTTP 错误 500 并在错误日志中收到此消息: [2018 年 3 月 13 日 08:47:07 UTC] PHP 致命错误:调用成员函数 get_id() 为 null /主页/

回答 2 投票 0

店铺页面显示单价,产品页面显示批发价格

在 Woocommerce 中,我已为我的产品设置了批发价。我试图仅在商店页面中显示产品的单价,该单价应该是批发价除以 6。 有线索吗?

回答 1 投票 0

在 WooCommerce 中应用零税时仅显示不含增值税的产品价格

我的 woocommerce 产品页面上显示了价格,其中显示了额外费用。增值税及公司当所选国家/地区的税率为 20% 时,增值税没问题,但是当我选择一个税率为 0% 的国家/地区时,我的价格就...

回答 1 投票 0

在 Woocommerce Force Sells 旁边添加价格

Woocommerce Force Sells 默认情况下仅列出产品标题。我还需要他们在每个标题旁边的括号中显示产品价格。您可以在这里看到它,如以下屏幕截图所示: 但它应该...

回答 1 投票 0

将购物车商品的价格替换为 Woocommerce 中的自定义字段值

在 WooCommerce 中,我尝试用自定义字段价格替换购物车商品的价格。 这是我的代码: 函数custom_cart_items_price ($cart_object) { 如果( is_admin() &&...

回答 1 投票 0

从格式化价格中提取数字以在 WooCommerce 中进行计算

我正在使用 Ewout Fernhout 的插件 WooCommerce PDF 发票和装箱单制作自定义发票模板,当我想创建更详细的产品列表时,我遇到了问题...

回答 1 投票 0

WooCommerce 中可变产品的有条件自定义价格后缀

我已为 Woocommerce 中的所有产品设置了价格后缀(在我的例子中为“每盒”)。这适用于可变产品以及单一产品,没有问题。 现在我想要这个前缀...

回答 1 投票 0

WooCommerce 中特定产品和特定客户的折扣

我正在尝试更改一位已登录客户的一种产品的价格。使用此代码时,价格确实会发生变化,但仅限于产品页面。我需要到处改变价格(存档,

回答 1 投票 0

仅针对 Woocommerce 中的特定产品设置购物车项目产品生成的销售价格

在 WooCommerce 3 中以编程方式仅设置特定产品销售价格后,相关购物车商品价格不会使用产品生成的销售价格进行更新。 我怎样才能得到生成...

回答 1 投票 0

隐藏产品价格和添加到购物车按钮,但不隐藏 WooCommerce 中未注册用户的变体

在我的 WooCommerce 商店中,我想隐藏价格,直到客户登录为止。我有以下代码可以实现这一点: add_action('init','hide_price'); 函数隐藏价格(...

回答 1 投票 0

在 WooCommerce 中动态设置产品变化自定义计算价格

当用户根据他们在产品页面中输入的内容结帐时,我尝试动态添加产品价格。价格设置仅适用于非变异产品。 ...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.