我是 php 的初学者,我试图在 php 文件中定位 3 个文本输出并为它们提供一个独特的类,以便我可以通过 css 对它们进行样式设置。
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
$customer_id = get_current_user_id();
if ( ! wc_ship_to_billing_address_only() && get_option( 'woocommerce_calc_shipping' ) !== 'no' ) {
$page_title = apply_filters( 'woocommerce_my_account_my_address_title', __('My Addresses:', 'woocommerce') );
$get_addresses = apply_filters( 'woocommerce_my_account_get_addresses', array(
'billing' => __( 'Billing Address:', 'woocommerce' ),
'shipping' => __( 'Shipping Address:', 'woocommerce' )
), $customer_id );
} else {
$page_title = apply_filters( 'woocommerce_my_account_my_address_title', __( 'My Address:', 'woocommerce' ) );
$get_addresses = apply_filters( 'woocommerce_my_account_get_addresses', array(
'billing' => __( 'Billing Address:', 'woocommerce' )
), $customer_id );
}
$col = 1;
?>
我正在尝试定位“我的地址:”以及“账单地址:”和“送货地址:”。
我以前用过这个,我从来没有在 php 代码中添加一个类,但它肯定是可能的,但我似乎找不到任何关于在哪里添加我的 div 类的信息, p类等。
如有任何帮助,我们将不胜感激!
非常感谢,
瓦亚
最佳答案
您可以使用 woocommerce 过滤器将其包装成您想要的任何东西。在您的 functions.php 中放入类似这样的内容:
function filter_woocommerce_my_account_my_address_title( $var ) {
return '<span class="your-class-here">'.$var.'</span>';
};
add_filter( 'woocommerce_my_account_my_address_title', 'filter_woocommerce_my_account_my_address_title', 10, 1 );
function filter_woocommerce_my_account_get_addresses( $array, $customer_id ) {
$array['billing'] = '<span class="class-name-here">'.$array['billing'].'</span>';
$array['shipping'] = '<span class="another-class-name-here">'.$array['shipping'].'</span>';
return $array;
};
add_filter( 'woocommerce_my_account_get_addresses', 'filter_woocommerce_my_account_get_addresses', 10, 2 );
请记住,如果这些元素是唯一的,id 属性可能是更好的选择。
希望对您有所帮助!
关于php - 在 Woocommerce 的 PHP 代码中插入类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36153109/