我有以下功能将选择列表添加到woo-commerce结帐表单:
woocommerce_form_field( 'airport_pickup', array(
'type' => 'select',
'class' => array('airport_pickup form-row-wide'),
'label' => __('Would you like us to arrange transportation from the airport to your starting hotel?'),
'required' => true,
'options' => array(
'Y' => __('YES'),
'N' => __('NO')
)), $checkout->get_value( 'airport_pickup' ));
Run Code Online (Sandbox Code Playgroud)
我想默认选择'NO'选项.请建议.怎么做?
我见过类似的问题,但找不到适合我的解决方案.
我正在尝试将自定义字段添加到WooCommerce注册表单,特别是名字和姓氏字段.我已设法创建这些字段,但输入的信息不会在用户登录时传递到"帐户详细信息"页面.其他教程已提到验证字段,但我不确定它是否与我相关.我正在研究Wordpress儿童主题.
请访问codepad .org查看代码.我尝试使用代码示例选项粘贴代码,但它无法正常工作.
希望我已经清楚地解释了自己.如果没有,请告诉我,我会澄清.
我得到此代码以向WooCommerce Billing表单添加自定义字段.
显示该字段但问题是该字段没有label也placeholder没有class name.
我在这里错过了什么?我将此代码添加到我的子主题中的functions.php中.
/*******************************
CUSTOM BILLING FIELD
******************************** */
add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');
function custom_woocommerce_billing_fields($fields)
{
$fields['billing']['billing_options'] = array(
'label' => __('NIF', 'woocommerce'), // Add custom field label
'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder
'required' => false, // if field is required or not
'clear' => false, // add clear or not
'type' => 'text', // add field type
'class' => array('my-css') // add class name
);
return …Run Code Online (Sandbox Code Playgroud) 使用WooCommerce和我在我的functions.php文件中进行一些自定义,以获取Cart页面上的自定义字段值.
我在添加到购物车之前添加自定义字段:
function add_name_on_tshirt_field() {
echo '<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label for="color">Name On T-Shirt</label></td>
<td class="value">
<input type="text" name="name-on-tshirt" value="" />
</td>
</tr>
</tbody>
</table>';
}
add_action( 'woocommerce_before_add_to_cart_button', 'add_name_on_tshirt_field' );
function render_meta_on_cart_item( $title = null, $cart_item = null, $cart_item_key = null ) {
if( $cart_item_key && is_cart() ) {
echo $title. '<dl class="">
<dt class="">Name On T-Shirt : </dt>
<dd class=""><p>'. WC()->session->get( $cart_item_key.'_name_on_tshirt') .'</p></dd>
</dl>';
}else {
echo $title;
}
/* $d=WC();
echo "<pre>";
print_r($d);*/
}
add_filter( 'woocommerce_cart_item_name', …Run Code Online (Sandbox Code Playgroud) 我有一种我不明白的奇怪行为
我已经更改了woocommerce_shop_loop_item_title挂钩以添加指向产品标题的链接.这是我在functions.php中的代码
// Add HREF TO TITLE
function abChangeProductsTitleHook(){
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
add_action('woocommerce_shop_loop_item_title', 'abChangeProductsTitle', 10 );
}
add_action( 'woocommerce_shop_loop_item_title', 'abChangeProductsTitleHook' );
function abChangeProductsTitle() {
echo '<h2 class="woocommerce-loop-product_title"><a href="'.get_the_permalink().'">' . get_the_title() . '</a></h2>';
}
Run Code Online (Sandbox Code Playgroud)
除了第一个产品外,它完美适用于所有产品.
我也对另一个钩子进行了类似的更改,将缩略图更改为背景图像,而且这个更改不适用于第一个产品.即使我改变产品的顺序,它也始终是第一个产品.
下面是页面上第一行产品的屏幕截图,第一行的显示方式不同
如果有人知道这个问题或者能指出我正确的方向,那将是非常有帮助的.
非常感谢Alex
在我的WooCommerce网站上,我正在使用此插件WooCommerce为客户取消订单,允许客户根据付款类型和时间取消订单。但是取消按钮仅出现在“ woocommerce_order_details_after_order_table”上。
我希望此取消按钮显示在“查看”按钮附近的“我的帐户”>“订单列表”中:

我试图编辑插件并添加以下代码: add_filter('woocommerce_my_account_my_orders_actions', array($this, 'order_cancel_button'), 10, 2);
但这不起作用:“查看”按钮消失了,“取消”按钮没有显示。
这是完整的代码:
<?php
/**
* Plugin Name: WooCommerce Order Cancel For Customers
* Plugin URI: https://wpmanageninja.com/plugins/order-cancel-for-customers-woocommerce
* Description: A tiny plugin that will enable customers to cancel woocommerce order within a certain amount of time.
* Version: 1.0
* Author: Techjewel
* Author URI: https://wpmanageninja.com
* Requires at least: 4.4
* Tested up to: 4.8
*
* Text Domain: wco
*
*/
// If this file is called …Run Code Online (Sandbox Code Playgroud) 在用户点击结帐后,我似乎找不到用于更改总数(或购物车的任何变量)的钩子。因此,例如,用户提交“结帐”表单,然后我需要做一些检查并相应地更改总数。
我该怎么做,我该使用哪个挂钩?
我可以在WooCommerce结帐屏幕上添加一组自定义字段,但需要将其移至“结算明细”上方。
那怎么办?
根据WooCommerce官方文档,这是添加额外的自定义结帐字段的示例代码:
/**
* Add the field to the checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Fill in this field'),
'placeholder' => __('Enter something'),
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
Run Code Online (Sandbox Code Playgroud) 我想在Woocommerce的帐户查看订单页面上添加图片。有人可以获取图片,但是尺寸太大,我不知道该在哪里添加此代码:
<?php
// Get a list of all items that belong to the order
$products = $order->get_items();
// Loop through the items and get the product image
foreach( $products as $product ) {
$product_obj = new WC_Product( $product["product_id"] );
echo $product_obj->get_image();
}
?>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激
这是我想添加产品图片的“查看订单”页面上的位置:
我的问题:如何在Woocommerce my-account/edit-account/页面中添加手机字段(相关模板:form-edit-account.php文件)
就像在以下答案中一样:
在WooCommerce我的帐户>帐户详细信息中保存自定义现场电话号码的值
但是,由于缺少一些挂钩函数,因此此答案代码不完整。感谢您提供任何帮助以完成某些事项,这意味着现场显示。
hook-woocommerce ×10
woocommerce ×10
wordpress ×10
php ×9
orders ×3
checkout ×2
cart ×1
forms ×1
image ×1