Ich möchte etwas CSS zur Bestellverwaltungsseite hinzufügen, um eine benutzerdefinierte Bestellaktionsschaltfläche auszublenden, aber nur, wenn die Bestellung nur herunterladbare Produkte enthält.
Dies ist die Funktion, die ich bedingt laden muss:
add_action( 'admin_head', 'hide_custom_order_status_dispatch_icon' );
function hide_custom_order_status_dispatch_icon() {
echo '<style>.widefat .column-order_actions a.dispatch { display: none; }</style>';
}
Ist das möglich?
Mit CSS ist es nicht möglich sein.
Stattdessen können Sie sich einklinken woocommerce_admin_order_actions
Filter-Hook, wo Sie prüfen können, ob alle Bestellartikel herunterladbar sind und dann die Aktionsschaltfläche entfernen können “versenden”:
add_filter( 'woocommerce_admin_order_actions', 'custom_admin_order_actions', 900, 2 );
function custom_admin_order_actions( $actions, $the_order ){
// If button action "dispatch" doesn't exist we exit
if( ! $actions['dispatch'] ) return $actions;
// Loop through order items
foreach( $the_order->get_items() as $item ){
$product = $item->get_product();
// Check if any product is not downloadable
if( ! $product->is_downloadable() )
return $actions; // Product "not downloadable" Found ==> WE EXIT
}
// If there is only downloadable products, We remove "dispatch" action button
unset($actions['dispatch']);
return $actions;
}
Der Code wird in der function.php-Datei des aktiven untergeordneten Designs (oder aktiven Designs) abgelegt.
Dies ist ungetestet, sollte aber funktionieren…
Das wirst du prüfen müssen 'dispatch'
ist der richtige Slug für diesen Aktionsknopf…
.