Files
mccans-theme/actions/WooCommerceBeforeAddToCartButtonAction.php
2025-10-07 16:28:31 -07:00

57 lines
1.3 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 (!is_array($attribute->get_options())) {
continue;
}
if (count($attribute->get_options()) < 1) {
continue;
}
if ($name === "Rental Rate (Daily)") {
$rentalRates["daily"] = $attribute->get_options()[0];
}
if ($name === "Rental Rate (Weekly)") {
$rentalRates["weekly"] = $attribute->get_options()[0];
}
if ($name === "Rental Rate (Monthly)") {
$rentalRates["monthly"] = $attribute->get_options()[0];
}
}
print_r($rentalRates);
echo "<p>yay!</p>";
}
}