我刚刚开始使用woocommerce.根据文档,我们需要将产品导入我们的数据库,这些数据库必须在我们的网站上列出.基本上我们正在开发的应用程序充当数据库的角色非常小的应用程序.供应商应用程序将提供API用于登录,注销,产品列表和所有内容.我需要做的就是在我的woocommerce应用程序中集成这些API.最好的方法是什么?有没有可用于实现这一目标的woocommerce挂钩?有没有办法从API而不是数据库中获取产品?
使用 woocommerce,我正在使用 Dokan 插件,并尝试在单个产品页面上显示供应商名称、评级和供应商位置。
我尝试使用此代码显示供应商名称,但没有运气:
//show store name
add_action( 'woocommerce_single_product_summary', 'show_store_name', 20 );
function show_store_name() {
printf( '<b>Seller Name:</b> <a href="%s">%s</a>', dokan_get_store_url( $author->ID ), $store_info['store_name'] );
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。
我希望在 WooCommerce 的购物车总计 div 中更改文本“购物车总计”,或者通过操作将其完全删除。
我在使用的框上方添加了不同的文本
add_action( 'woocommerce_before_cart_totals', 'custom_before_cart_totals' );
function custom_before_cart_totals() {
echo '<h2>Checkout</h2>';
}
Run Code Online (Sandbox Code Playgroud)
但是除了编辑 WooCommerce 模板或目标并使用 css 隐藏之外,我找不到删除默认措辞“购物车总计”的方法,但是我会喜欢我可以在函数文件中放置的内容来更改旧文本或将其完全删除.
任何意见,将不胜感激。
在前端显示按 SKU 搜索产品未找到产品。我创建了一个插件并尝试出错,但它始终显示找到 0 个产品。
add_action( 'pre_get_posts', 'wooSearchFrontEnd' );
function wooSearchFrontEnd( $query_vars ) {
global $typenow;
global $wpdb;
global $pagenow;
$search_term = $query_vars->query_vars['s'];
$search_postype = $query_vars->query_vars['post_type'];
if ( $search_term != '' && $search_postype == 'product' ) {
$meta_query = array( 'relation' => 'OR',
array(
'key' => '_sku',
'value' => get_query_var( 's' ),
'compare' => 'LIKE'
)
);
$query_vars->set( 'meta_query', $meta_query );
}
return $query_vars;
}
Run Code Online (Sandbox Code Playgroud) 我最近遇到了一个让我有点困惑的问题。在我的 WP 设置中,我有一个基本的 WooCommerce 解决方案(对于主题,我使用 Timber starter 主题来利用树枝模板)。除此之外,我正在使用名为“站点”的自定义帖子类型。站点代表建筑站点列表,不要与网站混淆。
Sites CPT 有 X 个高级自定义字段“字段”,以及标准的“标题”,ACF 字段是:
因此,管理员方面的上述大部分内容都是必需的,因此我们知道数据将存在。
我遇到的问题是,在结帐时,我们想要与上述字段匹配的字段,以及电子邮件地址字段(必填)和联系电话字段(必填)。
目的是,当客户输入他们的“职位编号”并点击“查找”按钮时,会启动一个查询,将该职位编号与自定义帖子类型上的职位编号字段进行匹配,如果找到匹配项,该记录中的其他字段填写到结帐表单的其余部分中。
在尝试解决方案方面,我唯一能做的就是匹配和返回数据的数据库查询,但我对 WP 整体还是相当陌生,而且似乎有一些概念,例如 Ajax 具有特定用例在 WP 中,DB 结构似乎很复杂,所以我想我会在这里问一下,看看是否有人有解决方案。
到目前为止,没有代码可以显示,否则我会显示,并且就 WooCommerce 模板而言,它们都是标准的并且没有被修改。
总结一下,目标是:
客户去结帐 -> 输入他们已知的工作编号并点击“查找”-> 运行某种查询以将该工作编号与工作编号的 CPT ACF 字段进行匹配 -> 如果找到匹配项,则返回这些字段并使用该数据填写 Woo Checkout …
我编写了一些代码,用于在基于产品类别的产品详细信息页面上显示自定义缺货消息。
function custom_backorder_message( $text, $product ){
if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {
if( has_term( 'bridal-line', 'product_cat' ) ) {
$text = __( 'Your piece will be handcrafted for you. Upon order we will manufacture your piece of eternity. Sadly, we can not give you a timeline, due to Covid 19, but are expecting 5-7 weeks', 'text-domain' );
}else {
$text = __( 'This product is currently out of stock, but upon order we will handcraft your piece. …Run Code Online (Sandbox Code Playgroud) 我的联盟脚本跟踪下订单后的转化。它在动作挂钩内运行woocommerce_thankyou:
function affiliate_tracking_code( $order_id ) {
// get the order info for the script
?>
<script>
// affiliate script here
</script>
<?php
}
add_action( 'woocommerce_thankyou', 'affiliate_tracking_code', 10, 1 );
Run Code Online (Sandbox Code Playgroud)
如果订单失败或待处理,我不希望触发此脚本。只要成功的话。我在文档中找不到woocommerce_thankyou除了成功订单之外是否会触发操作挂钩。
如果确实如此,那么确保我的脚本仅跟踪成功订单而不跟踪失败订单的转化的最佳方法是什么?
我测试过的一种方法是将我的脚本包装在 if 和 check 中if ( $order->get_status() == 'processing' ) : // run the script,但是我不确定是否存在隐藏的漏洞。
我创建了一个名为“批发商”的新角色。该角色按预期发挥作用。
我还创建了一个名为“批发商价格”的自定义价格字段。它也按预期工作。
我检查用户角色,如果他们被分配为批发商,我会给他们定制产品价格(如果已填写)。我一切都在工作,除了我无法弄清楚最后的部分。如何提取当前产品 ID、获取批发价格并分配它。我的functions.php代码如下:
/* Custom user roles */
add_role( 'wholesaler', 'Wholesaler', get_role( 'customer' )->capabilities );
add_action( 'woocommerce_product_options_pricing', 'action_woocommerce_product_options_pricing', 10, 0 );
/* Add custom wholesaler price field to general page */
function action_woocommerce_product_options_pricing() {
woocommerce_wp_text_input( array(
'id' => 'wholesaler_price',
'class' => 'wc_input_price short',
'label' => __( 'Wholesaler price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',
) );
}
// Save Fields
function action_woocommerce_admin_process_product_object( $product ) {
if( isset($_POST['wholesaler_price']) ) {
$product->update_meta_data( 'wholesaler_price', sanitize_text_field( $_POST[ 'wholesaler_price'] ) ); …Run Code Online (Sandbox Code Playgroud) 使用添加在 WooCommerce 4+ 答案代码中发送电子邮件通知的新订单状态,我已经能够收到一个自定义状态的电子邮件通知,但无法了解如何发送电子邮件通知两种自定义状态。
请参阅下面的示例代码和我尝试过的多个自定义状态电子邮件通知的代码。我还包含了完整的代码,它显示了创建多个状态的整个过程。
希望对这个快速修复有所帮助!
另外,至于电子邮件正文 - 是否有可能通过此代码更改处理订单内容,而无需创建新的电子邮件模板?
正在运行 - 单个自定义状态电子邮件通知“已发货”
add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_wc-shipped';
return $actions;
}
// Send Customer Processing Order email notification when order status get changed from "tree" to "processing"
add_action('woocommerce_order_status_changed', 'shipped_status_custom_notification', 10, 4);
function shipped_status_custom_notification( $order_id, $from_status, $to_status, $order ) {
if( 'shipped' === $to_status ) {
// The email notification type
$email_key = 'WC_Email_Customer_Processing_Order';
// Get specific WC_emails object
$email_obj = WC()->mailer()->get_emails()[$email_key];
// Sending …Run Code Online (Sandbox Code Playgroud) 我是 WordPress 开发新手,目前遇到了死胡同。
我希望在订单状态更改后在 WooCommerce 订单中显示管理员通知。
使用以下代码,不会出现该通知:
<?php
class TestNotice {
public function testTheNotice() {
add_action('woocommerce_order_status_changed', [$this, 'test'], 10, 4);
}
public function test(int $id, string $statusFrom, string $statusTo, WC_Order $order)
{
add_action('admin_notices', [$this, 'notice']);
}
public function notice()
{
?>
<div class="notice notice-error is-dismissible">
<p>This notice appears on the order page.</p>
</div>
<?php
}
}
$testNotice = new TestNotice();
$testNotice->testTheNotice();
Run Code Online (Sandbox Code Playgroud)
我尝试将“admin_notices”操作的“优先级”参数设置为20,但没有成功(我认为如果嵌套操作与第一次调用的操作相同,这会很有用)。
但是,当我直接在方法中调用“admin_notices”操作testTheNotice()(因此不调用“woocommerce_order_status_changed”操作)时,它可以工作(在每个管理页面上,这不是我想要的)。
我以为这是因为notice()不知何故无法识别,但实际上是:下面的代码显示“此通知出现在订单页面上”。在空白页上(这不是我想要的,仅用于测试目的)。
<?php
class TestNotice {
public function testTheNotice() {
add_action('woocommerce_order_status_changed', [$this, …Run Code Online (Sandbox Code Playgroud) hook-woocommerce ×10
php ×10
woocommerce ×10
wordpress ×10
orders ×2
api ×1
cart ×1
dokan ×1
price ×1