标签: hook-woocommerce

在 Woocommerce 中将产品描述移至简短描述之后

我已使用此挂钩的第一个选项(其他选项不起作用)->所有产品的 Woocommerce 产品默认描述

这就是它的样子(红色标记的文字是标准描述)

但是,我希望文本出现在产品描述之后。红色箭头所在的位置是标准文本。所以上面的“in winkelmand”(意思是“添加到购物袋”)

我怎样才能实现这个目标?

php wordpress product woocommerce hook-woocommerce

4
推荐指数
2
解决办法
9014
查看次数

让美国在 Woocommerce 结账国家/地区中排名第一 选择字段

我已在 woocommerce 结帐中选择美国作为我的默认国家/地区。除此之外,我还被要求将“美国”移至结账表单中国家/地区列表的最顶部。

我创建了一个新的过滤器并连接到“woocommerce_countries”挂钩,如下所示:

function change_country_order_in_checkout_form($countries)
{
    $countries = array('US' => $countries['US']) + $countries;

    return $countries;
}

add_filter( 'woocommerce_countries', 'change_country_order_in_checkout_form' );
Run Code Online (Sandbox Code Playgroud)

我的国家/地区列表已正确修改,但随后 WooCommerce 中的某些内容按字母顺序对国家/地区进行排序,我想避免这种情况。我尝试添加:

remove_filter('woocommerce_sort_countries', 'wpautop');
Run Code Online (Sandbox Code Playgroud)

但这似乎没有什么区别。任何帮助表示赞赏。

php wordpress countries woocommerce hook-woocommerce

4
推荐指数
1
解决办法
2432
查看次数

将子菜单条目添加到 WooCommerce“产品”管理菜单

我想在 WooCommerce“产品”管理菜单下添加一个子菜单条目。有人知道这个菜单的 $parent_slug 是什么吗?

add_submenu_page我可以使用'woocommerce' for $parent_slug(通过钩子)将子菜单项添加到“WooCommerce”菜单中admin_menu,但似乎无法弄清楚$parent_slug产品菜单的子菜单项是什么......

if ( is_admin() ) {
    add_action( 'admin_menu', 'add_products_menu_entry', 100 );
}

function add_products_menu_entry() {
    add_submenu_page(
        'woocommerce-product', // This is what I can't figure out
        __( 'Product Grabber' ),
        __( 'Grab New' ),
        'manage_woocommerce', // Required user capability
        'ddg-product',
        'generate_grab_product_page'
    );
}

function generate_grab_product_page() {
  // Page generation code will go here
}
Run Code Online (Sandbox Code Playgroud)

WooCommerce 产品管理菜单

在此输入图像描述

php wordpress backend woocommerce hook-woocommerce

4
推荐指数
1
解决办法
2170
查看次数

Woocommerce 单一产品页面挂钩

如何显示单个产品图像上方描述部分的段落?

我确实尝试过使用钩子但仍然没有成功

wordpress woocommerce hook-woocommerce

4
推荐指数
1
解决办法
2万
查看次数

如何禁用 WooCommerce 预订产品的运输结帐字段

我知道我可以通过在产品提交表单上选中“虚拟”来自动禁用送货字段 - 但如何在默认情况下禁用 Woocommerce 预订产品结账时的送货字段(对于“预订”产品类型)?

php wordpress woocommerce hook-woocommerce woocommerce-bookings

4
推荐指数
1
解决办法
1987
查看次数

自定义 WooCommerce 我的帐户和结账上的地址字段

我正在使用woocommerce_checkout_fields过滤器来编辑 woocommerce 字段标签的值。它在结账页面上运行良好(正如您所期望的那样),但是我无法理解为什么它在帐户页面上不起作用。我以为这些田地还是从同一个地方取来的?更具体地说,我谈论的是 woocommerce 帐户页面上编辑地址端点上的地址字段?

我的代码尝试:

function custom_woocommerce_fields( $fields ) {

    // Billing Fields
    $fields['billing']['billing_first_name']['label'] = 'First name';
    $fields['billing']['billing_last_name']['label'] = 'Last name';
    $fields['billing']['billing_company']['label'] = 'Company name';
    $fields['billing']['billing_address_1']['label'] = 'Street address';
    $fields['billing']['billing_address_2']['label'] = 'Apartment, unit, etc.';
    $fields['billing']['billing_city']['label'] = 'City';
    $fields['billing']['billing_country']['label'] = 'Country';
    $fields['billing']['billing_state']['label'] = 'County/State';
    $fields['billing']['billing_postcode']['label'] = 'Postcode';
    $fields['billing']['billing_email']['label'] = 'Email';
    $fields['billing']['billing_phone']['label'] = 'Phone';

    // Shipping Fields
    $fields['shipping']['shipping_first_name']['label'] = 'First name';
    $fields['shipping']['shipping_last_name']['label'] = 'Last name';
    $fields['shipping']['shipping_company']['label'] = 'Company name';
    $fields['shipping']['shipping_address_1']['label'] = 'Street address';
    $fields['shipping']['shipping_address_2']['label'] = 'Apartment, unit, etc.';
    $fields['shipping']['shipping_city']['label'] …
Run Code Online (Sandbox Code Playgroud)

php wordpress checkout woocommerce hook-woocommerce

4
推荐指数
1
解决办法
8108
查看次数

WooCommerce:仅在单个产品页面上显示价格后缀 - 不适用于相关产品

我试图仅在产品页面上的价格后面显示后缀。我不想在其他地方显示这个后缀。

我没有使用“税收”设置,因为我的价格已包含在内,并且我不想使用“税收”选项使设置变得复杂。

使用此答案中代码片段中的第一条路线/sf/answers/4005328631/

我的代码是:

## Add suffix to price on Product Page
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
function custom_price_suffix( $price, $product ) {
    if(is_singular('product')) {
        $price = $price . ' <span class="make-me-small"> Inclusive of all taxes</span>';
    }
    return apply_filters( 'woocommerce_get_price', $price );
}
##-End of above code - Start new code below
Run Code Online (Sandbox Code Playgroud)

但是,此代码片段显示了相关产品中的后缀。

我应该做什么更改才能防止在相关产品中显示后缀

php wordpress woocommerce hook-woocommerce

4
推荐指数
1
解决办法
1390
查看次数

使用 Hook 删除 WooCommerce 营销菜单项 (wp-admin)

随着新的 WooCommerce 4.1.0 刚刚发布,菜单中出现了一个新的营销项目。查看 URL,它转到admin.php?page=wc-admin&path=/marketing并通过使用admin_menu挂钩,我试图删除此菜单选项。

我尝试使用sub_menu选项和remove_menu_page选项但没有成功。如果有人可以纠正我的代码,我将非常感激。

add_action( 'admin_menu', 'remove_woocommerce_marketing_menu_option' );
function remove_woocommerce_marketing_menu_option(){
remove_menu_page( 'admin.php?page=wc-admin&path=/marketing' );
}
Run Code Online (Sandbox Code Playgroud)

php wordpress woocommerce hook-woocommerce

4
推荐指数
1
解决办法
2783
查看次数

更改“woocommerce_template_loop_product_title”标题标签

我正在尝试将 WooCommercewoocommerce-loop-product__title从 a更改H2为 a h6,但遇到了一些麻烦。

我使用以下代码片段来取消原始函数并将其替换为h6. 不幸的是,这确实添加了h6但它也保留了原来的h2.

有人能指出哪里出了问题吗?

remove_action( 'woocommerce_shop_loop_item_title','woocommerce_template_loop_product_title', 10 );
add_action('woocommerce_shop_loop_item_title', 'soChangeProductsTitle', 10 );
function soChangeProductsTitle() {
    echo '<h6 class="' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">' . get_the_title() . '</h6>';
}
Run Code Online (Sandbox Code Playgroud)

php wordpress woocommerce hook-woocommerce

4
推荐指数
1
解决办法
2665
查看次数

挂钩添加到 Woocommerce 的购物车

我正在使用 WC Marketplace 经营 WooCommerce 商店。我试图用下面的钩子实现的是,如果篮子中已经有来自不同供应商的产品,则防止将新项目添加到篮子中。例如,如果购物者将来自供应商 y 的产品 x 添加到他的购物篮中,如果他们要添加来自供应商 b 的产品 a,则不会添加该项目并且用户将被告知错误。

我有两个问题:
- 首先,钩子什么时候运行,是在主函数触发之前还是之后?我有一个函数的钩子woocommerce_add_to_cart。所以我想知道钩子会在函数woocommerce_add_to_cart运行之后还是之前触发。
- 我的第二个问题是,我在下面附上了钩子,您认为这行得通吗?

function action_woocommerce_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) { 
    $same_vendor = 1;

    $empty = WC_Cart::is_empty();

    //If there is an item in the cart then,
    if (!$empty) {
        //Get the VendorId of the product being added to the cart.
        $vendor = get_wcmp_product_vendors($product_id);
        $vendor_id = $vendor->id;

        foreach( WC()->cart->get_cart() as $cart_item ) {
            //Get the vendor Id of the item …
Run Code Online (Sandbox Code Playgroud)

php wordpress cart woocommerce hook-woocommerce

3
推荐指数
1
解决办法
4355
查看次数