這是我向訂單頁面添加選項的功能:
add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_my_orders_custom_action', 10, 2 );
function add_my_account_my_orders_custom_action( $actions, $order ) {
$action_slug = 'specific_name';
$actions[$action_slug] = array(
'url' => home_url('/the_action_url/'),
'name' => 'The Button Text',
);
return $actions;
}
我的問題是:如何將我的自定義 CSS 添加到僅我新創建的選項
(除了我的按鈕之外,還有其他 3 個按鈕,我不想更改它們的樣式,并且所有 4 個按鈕都具有相同的類)。
uj5u.com熱心網友回復:
在前端顯示按鈕時,動作鍵被分配為類名,因此您可以根據動作鍵分配不同的 CSS,如下所示:
.shop_table .button.specific_name {
color: #fff;
}
uj5u.com熱心網友回復:
使用$action_slug = 'specific_name';會自動將它作為一個類添加到按鈕中。
然后你可以使用下面的選擇器
.woocommerce-account table.account-orders-table .specific_name {
color: red;
}
專門應用 CSS 或覆寫現有的 CSS
要執行相反的操作并洗掉此特定按鈕的某些類,除了現有代碼之外,您還需要覆寫模板檔案/myaccount/orders.php
- 可以通過將其復制到
yourtheme/woocommerce/myaccount/orders.php.
替換第 69 - 71 行 @version 3.7.0
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
echo '<a href="' . esc_url( $action['url'] ) . '" hljs-variable">$key ) . '">' . esc_html( $action['name'] ) . '</a>';
}
和
foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
// Compare
if ( $key == 'specific_name' ) {
echo '<a href="' . esc_url( $action['url'] ) . '" hljs-variable">$key ) . '">' . esc_html( $action['name'] ) . '</a>';
} else {
echo '<a href="' . esc_url( $action['url'] ) . '" hljs-variable">$key ) . '">' . esc_html( $action['name'] ) . '</a>';
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/336964.html
標籤:php css WordPress的 求购 订单
