Files
mccans-theme/actions/WooCommerceBeforeAddToCartButtonAction.php
2025-10-07 16:26:47 -07:00

49 lines
1.1 KiB
PHP

<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceBeforeAddToCartButtonAction extends RadAction
{
/**
* @var string WordPress hook to attach to.
*/
protected string $hookName = 'woocommerce_before_add_to_cart_button';
/**
* @var int Hook priority.
*/
protected int $priority = 10;
/**
* Your action callback.
*/
public function callback()
{
global $product;
if (!$product || !is_a($product, 'WC_Product')) {
return;
}
$attributes = $product->get_attributes();
$rentalRates = [];
foreach ($attributes as $attribute) {
$name = $attribute->get_name();
if ($name === "Rental Rate (Daily)") {
$rentalRates["daily"] = $attribute->get_options();
}
if ($name === "Rental Rate (Weekly)") {
$rentalRates["weekly"] = $attribute->get_options();
}
if ($name === "Rental Rate (Monthly)") {
$rentalRates["monthly"] = $attribute->get_options();
}
}
print_r($rentalRates);
echo "<p>yay!</p>";
}
}